[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Various retain/release bugs
From: |
Alexander Malmberg |
Subject: |
Re: Various retain/release bugs |
Date: |
Thu, 21 Feb 2002 15:16:47 +0100 |
> 3.
> NSMenu retains its NSMenuView; NSMenuView retains its NSMenu; NSMenuView
> retains its NSMenuItemCell:s and they retain the NSMenuView, etc. Either
> I'm missing something about how this is supposed to work or something is
> really messed up here.
After more investigation, I managed to patch this by changing the
retains and releases to normal assignments. I've attached a patch that
does this, but it probably breaks encoding/decoding. I think I've fixed
the encoding and decoding in NSMenuView and NSMenuItemCell, but I'm not
sure what NSMenu should do (it's not encoding its NSMenuView). Someone
who knows how it's supposed to work should probably look at it.
When that was fixed, I had to patch a bug in [NSApplication -dealloc].
It was using TEST_RELEASE to free the menus, but releasing _windows_menu
caused the menu's window to be closed and NSApplication was trying to
update the windows menu using the (now invalid) _windows_menu object. I
changed the TEST_RELEASE:s to DESTROY:s and it worked. I've attached a
patch.
Now that my windows are being dealloc:d properly, they keep forgetting
their frames. Turns out [NSWindow -dealloc] is calling [self
setFrameAutosaveName: nil] which makes setFrameAutosaveName remove the
defaults key for the old name. I've attached a patch that makes dealloc
remove the entry from _autosaveNames manually.
- Alexander Malmberg
Index: NSApplication.m
===================================================================
RCS file: /cvsroot/gnustep/gnustep/core/gui/Source/NSApplication.m,v
retrieving revision 1.195
diff -u -r1.195 NSApplication.m
--- NSApplication.m 17 Feb 2002 23:38:34 -0000 1.195
+++ NSApplication.m 21 Feb 2002 11:26:27 -0000
@@ -736,8 +736,8 @@
NSZoneFree(NSDefaultMallocZone(), tmp);
}
- TEST_RELEASE(_main_menu);
- TEST_RELEASE(_windows_menu);
+ DESTROY(_main_menu);
+ DESTROY(_windows_menu);
TEST_RELEASE(_app_icon);
TEST_RELEASE(_app_icon_window);
TEST_RELEASE(_infoPanel);
Index: NSMenuItemCell.m
===================================================================
RCS file: /cvsroot/gnustep/gnustep/core/gui/Source/NSMenuItemCell.m,v
retrieving revision 1.27
diff -u -r1.27 NSMenuItemCell.m
--- NSMenuItemCell.m 14 Feb 2002 13:36:37 -0000 1.27
+++ NSMenuItemCell.m 21 Feb 2002 11:26:27 -0000
@@ -77,7 +77,7 @@
- (void) dealloc
{
RELEASE(_menuItem);
- RELEASE(_menuView);
+ _menuView=nil;
[super dealloc];
}
@@ -105,7 +105,7 @@
- (void) setMenuView:(NSMenuView *)menuView
{
- ASSIGN(_menuView, menuView);
+ _menuView = menuView;
if ([[_menuView menu] _ownedByPopUp])
{
_mcell_belongs_to_popupbutton = YES;
@@ -646,7 +646,7 @@
if (_menuItem)
c->_menuItem = [_menuItem copyWithZone: zone];
- c->_menuView = RETAIN(_menuView);
+ c->_menuView = _menuView;
return c;
}
@@ -659,7 +659,6 @@
[super encodeWithCoder: aCoder];
[aCoder encodeConditionalObject: _menuItem];
- [aCoder encodeConditionalObject: _menuView];
}
- (id) initWithCoder: (NSCoder*)aDecoder
@@ -667,7 +666,6 @@
[super initWithCoder: aDecoder];
_menuItem = [aDecoder decodeObject];
- _menuView = [aDecoder decodeObject];
_needs_sizing = YES;
Index: NSMenuView.m
===================================================================
RCS file: /cvsroot/gnustep/gnustep/core/gui/Source/NSMenuView.m,v
retrieving revision 1.55
diff -u -r1.55 NSMenuView.m
--- NSMenuView.m 11 Feb 2002 14:06:00 -0000 1.55
+++ NSMenuView.m 21 Feb 2002 11:26:27 -0000
@@ -96,7 +96,7 @@
{
RELEASE(_font);
RELEASE(_itemCells);
- TEST_RELEASE(_menu);
+ _menu = nil;
[super dealloc];
}
@@ -114,7 +114,8 @@
[theCenter removeObserver: self name: nil object: _menu];
}
- ASSIGN(_menu, menu);
+ _menu = menu;
+
_items_link = [_menu itemArray];
// Add this menu view to the menu's list of observers.
@@ -1075,6 +1076,8 @@
[decoder decodeValueOfObjCType: @encode(BOOL) at: &_horizontal];
[decoder decodeValueOfObjCType: @encode(float) at: &_horizontalEdgePad];
[decoder decodeValueOfObjCType: @encode(NSSize) at: &_cellSize];
+
+ [_itemCells makeObjectsPerformSelector: @selector(setMenuView:) withObject:
self];
_highlightedItemIndex = -1;
_needsSizing = YES;
Index: NSWindow.m
===================================================================
RCS file: /cvsroot/gnustep/gnustep/core/gui/Source/NSWindow.m,v
retrieving revision 1.218
diff -u -r1.218 NSWindow.m
--- NSWindow.m 19 Feb 2002 02:33:52 -0000 1.218
+++ NSWindow.m 21 Feb 2002 11:26:28 -0000
@@ -590,7 +590,14 @@
argument: nil];
[NSApp removeWindowsItem: self];
- [self setFrameAutosaveName: nil];
+ [windowsLock lock];
+ if (_autosaveName != nil)
+ {
+ [autosaveNames removeObject: _autosaveName];
+ _autosaveName = nil;
+ }
+ [windowsLock unlock];
+
if (_counterpart != 0 && (_styleMask & NSMiniWindowMask) == 0)
{
NSWindow *mini = [NSApp windowWithWindowNumber: _counterpart];