FROM : Joe Esch
DATE : Thu Nov 14 19:38:03 2002
I have an NSPopUpButton on a panel and I want to build its menu
dynamically from the contents of a folder. I had it all working OK,
and then I wanted to modify it so that I could refresh the menu if the
folder contents may have changed.
To do this, I just sent removeAllItems to my NSPopUpButton and then
added the new menu items. After I made this change, things started
crashing at seemingly random times (although always while building the
menu.)
The symptoms look like various NSStrings that I got before calling
removeAllItems (strings that were not in the menu) are being released.
These are all strings that should be autoreleased.
My understanding of autorelease is that unless you explicitly cause the
autorelease pool to do an autorelease, your objects will get released
sometime in the future, but they will stay around within the current
call frame.
My question is if there is any way that the removeAllObjects call could
be forcing an early autorelease and thus causing my strings to go away.
I fixed the problem by not using removeAllObjects and just manually
removing them by calling removeItemAtIndex multiple times. I would
like to understand what was going on however so that I can avoid
problems like this in the future.
DATE : Thu Nov 14 19:38:03 2002
I have an NSPopUpButton on a panel and I want to build its menu
dynamically from the contents of a folder. I had it all working OK,
and then I wanted to modify it so that I could refresh the menu if the
folder contents may have changed.
To do this, I just sent removeAllItems to my NSPopUpButton and then
added the new menu items. After I made this change, things started
crashing at seemingly random times (although always while building the
menu.)
The symptoms look like various NSStrings that I got before calling
removeAllItems (strings that were not in the menu) are being released.
These are all strings that should be autoreleased.
My understanding of autorelease is that unless you explicitly cause the
autorelease pool to do an autorelease, your objects will get released
sometime in the future, but they will stay around within the current
call frame.
My question is if there is any way that the removeAllObjects call could
be forcing an early autorelease and thus causing my strings to go away.
I fixed the problem by not using removeAllObjects and just manually
removing them by calling removeItemAtIndex multiple times. I would
like to understand what was going on however so that I can avoid
problems like this in the future.
| Related mails | Author | Date |
|---|---|---|
| Joe Esch | Nov 14, 19:38 | |
| Eyal Redler | Nov 15, 17:02 |






Cocoa mail archive

