diff --git a/ChangeLog b/ChangeLog index c73cc7de..4fd9dfb7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2004-07-17 17:54 Gregory John Casamento + + * GormDocument.m: Leak fixes and general clean up. + * GormGenericEditor.m: Same. + * GormImageEditor.m: Same. + * GormViewEditor.h: Same. + * GormWindowEditor.m: Same. + * Palettes/0Menus/GormMenuEditor.m: Same. + * Palettes/0Menus/GormNSMenu.m: Same. + * Palettes/1Windows/GormNSPanel.h: Added new method so that the + window setting "is released when closed" is saved, but doesn't + effect the window displayed in Gorm. This presents some tricky + memory management problems. + * Palettes/1Windows/GormNSPanel.m: Same. + * Palettes/1Windows/GormNSWindow.h: Same. + * Palettes/1Windows/GormNSWindow.m: Same. + * Palettes/1Windows/main.m: Added code necessary in the + inspector to use the new method. + 2004-07-17 17:54 Gregory John Casamento * GormFilePrefsManager.m: Removed reference to math.h and values.h diff --git a/GormDocument.m b/GormDocument.m index 7481d1fe..e191f430 100644 --- a/GormDocument.m +++ b/GormDocument.m @@ -425,7 +425,8 @@ static NSImage *fileImage = nil; toolbar = [[NSToolbar alloc] initWithIdentifier: @"GormToolbar"]; [toolbar setAllowsUserCustomization: NO]; [toolbar setDelegate: self]; - [window setToolbar: toolbar]; + [window setToolbar: toolbar]; + RELEASE(toolbar); [toolbar setUsesStandardBackgroundColor: YES]; } @@ -1052,25 +1053,42 @@ static NSImage *fileImage = nil; - (void) dealloc { [[NSNotificationCenter defaultCenter] removeObserver: self]; + + // close the window... [window close]; - // [toolbar setDelegate: nil]; + + // Get rid of the selection box. + [selectionBox removeFromSuperviewWithoutNeedingDisplay]; + + // release the managers... RELEASE(classManager); + RELEASE(filePrefsManager); + + // release editors... RELEASE(classEditor); + RELEASE(savedEditors); + RELEASE(openEditors); + + // hidden objects... RELEASE(hidden); - RELEASE(filesOwner); - RELEASE(firstResponder); - RELEASE(fontManager); + + // release special objects... + // RELEASE(filesOwner); + // RELEASE(firstResponder); + // RELEASE(fontManager); + if (objToName != 0) { NSFreeMapTable(objToName); } + RELEASE(documentPath); - RELEASE(savedEditors); RELEASE(scrollView); RELEASE(classesScrollView); - RELEASE(toolbar); - RELEASE(filePrefsManager); - RELEASE(openEditors); + RELEASE(soundsScrollView); + RELEASE(imagesScrollView); + + // NSLog(@"window = %@",window); RELEASE(window); [super dealloc]; } @@ -1553,6 +1571,7 @@ static NSImage *fileImage = nil; [editors addObjectsFromArray: openEditors]; [editors makeObjectsPerformSelector: @selector(close)]; [openEditors removeAllObjects]; + // [editors makeObjectsPerformSelector: @selector(release)]; [editors removeAllObjects]; // Close the editors in the document window... @@ -1577,35 +1596,29 @@ static NSImage *fileImage = nil; enumerator = [nameTable objectEnumerator]; while ((obj = [enumerator nextObject]) != nil) { + /* if ([obj isKindOfClass: [NSMenu class]] == YES) { if ([[obj window] isVisible] == YES) { - [hidden addObject: obj]; [obj close]; } } - else if ([obj isKindOfClass: [NSWindow class]] == YES) + else + */ + if ([obj isKindOfClass: [NSWindow class]] == YES) { - [obj setReleasedWhenClosed: NO]; - if ([obj isVisible] == YES) - { - [hidden addObject: obj]; - [obj orderOut: self]; - } + [obj setReleasedWhenClosed: YES]; + [obj close]; } } - + // deactivate the document... [self setDocumentActive: NO]; [self setSelectionFromEditor: nil]; [self closeAllEditors]; // shut down all of the editors.. - [nc postNotificationName: IBWillCloseDocumentNotification - object: self]; + [nc postNotificationName: IBWillCloseDocumentNotification object: self]; [nc removeObserver: self]; // stop listening to all notifications. - // [window setToolbar: nil]; // close the toolbar - // [toolbar setDelegate: nil]; // unset the delegate... - // RELEASE(self); } else if ([name isEqual: NSWindowDidBecomeKeyNotification] == YES) { @@ -2437,7 +2450,6 @@ static NSImage *fileImage = nil; [self setName: @"My Window" forObject: aWindow]; [self attachObject: aWindow toParent: nil]; [self setObject: aWindow isVisibleAtLaunch: YES]; - RELEASE(aWindow); [aMenu setTitle: _(@"Main Menu")]; [aMenu addItemWithTitle: _(@"Hide") @@ -2449,9 +2461,8 @@ static NSImage *fileImage = nil; // the first menu attached becomes the main menu. [self attachObject: aMenu toParent: nil]; - [objectsView addObject: aMenu]; [[aMenu window] setFrameTopLeftPoint: origin]; - RELEASE(aMenu); + // RETAIN(aMenu); } else if ([type isEqual: @"Inspector"] == YES) { @@ -2481,7 +2492,7 @@ static NSImage *fileImage = nil; [aWindow setTitle: _(@"Inspector Window")]; [self setName: @"InspectorWin" forObject: aWindow]; [self attachObject: aWindow toParent: nil]; - RELEASE(aWindow); + // RELEASE(aWindow); } else if ([type isEqual: @"Palette"] == YES) { @@ -2511,7 +2522,7 @@ static NSImage *fileImage = nil; [aWindow setTitle: _(@"Palette Window")]; [self setName: @"PaletteWin" forObject: aWindow]; [self attachObject: aWindow toParent: nil]; - RELEASE(aWindow); + // RELEASE(aWindow); } } @@ -2528,6 +2539,7 @@ static NSImage *fileImage = nil; NSDebugLog(@"Attempt to set name for nil object"); return; } + if (aName == nil) { /* @@ -2588,7 +2600,7 @@ static NSImage *fileImage = nil; } nameCopy = [aName copy]; /* Make sure it's immutable */ [nameTable setObject: object forKey: nameCopy]; - AUTORELEASE(object); // make sure that when it's removed from the table, it's released. + RELEASE(object); // make sure that when it's removed from the table, it's released. NSMapInsert(objToName, (void*)object, (void*)nameCopy); if (oldName != nil) { diff --git a/GormGenericEditor.m b/GormGenericEditor.m index a48ba3ae..c6337e34 100644 --- a/GormGenericEditor.m +++ b/GormGenericEditor.m @@ -143,7 +143,7 @@ if(closed == NO) [self close]; - // RELEASE(objects); // FIXME: This will leak... + RELEASE(objects); // [super dealloc]; } diff --git a/GormImageEditor.m b/GormImageEditor.m index 1f1fb6c8..35d0bc30 100644 --- a/GormImageEditor.m +++ b/GormImageEditor.m @@ -244,6 +244,7 @@ static int handled_mask= NSDragOperationCopy|NSDragOperationGeneric|NSDragOperat GormImage *image = [[GormImage alloc] initWithName: name path: obj]; [image setSystemImage: YES]; [self addObject: image]; + RELEASE(image); } // set up the notification... @@ -469,9 +470,16 @@ static int handled_mask= NSDragOperationCopy|NSDragOperationGeneric|NSDragOperat [self setNeedsDisplay: YES]; } +/* +- (void) dealloc +{ + NSLog(@"deallocing.."); + [super dealloc]; +} +*/ @end -// sound proxy object... +// image proxy object... @implementation GormImage - (id) initWithName: (NSString *)aName path: (NSString *)aPath @@ -520,6 +528,7 @@ static int handled_mask= NSDragOperationCopy|NSDragOperationGeneric|NSDragOperat RELEASE(name); RELEASE(path); RELEASE(image); + RELEASE(smallImage); [super dealloc]; } diff --git a/GormViewEditor.h b/GormViewEditor.h index c1cb523c..62008e0b 100644 --- a/GormViewEditor.h +++ b/GormViewEditor.h @@ -32,10 +32,10 @@ @interface GormViewEditor : NSView { - id document; - NSView *_editedObject; - BOOL activated; - BOOL closed; + id document; + id _editedObject; + BOOL activated; + BOOL closed; GormViewWithSubviewsEditor *parent; } - (BOOL) activate; diff --git a/GormWindowEditor.m b/GormWindowEditor.m index a654ee9f..1a83095f 100644 --- a/GormWindowEditor.m +++ b/GormWindowEditor.m @@ -46,12 +46,27 @@ { NSBundle *bundle = [NSBundle mainBundle]; NSString *path = [bundle pathForImageResource: @"GormWindow"]; - image = [[NSImage alloc] initWithContentsOfFile: path]; } return image; } +@end +@interface NSWindow (GormWindowEditorAdditions) +- (void) unsetInitialFirstResponder; +@end + +@implementation NSWindow (GormWindowEditorAdditions) +/* + * The setFirstResponder method is used in this editor to allow it to + * respond to messages forwarded to the window appropriately. + * Unfortunately, once it's set to something, it cannot be set to nil. + * This method allows us to set it to nil, thus preventing a memory leak. + */ +- (void) unsetInitialFirstResponder +{ + ASSIGN(_initialFirstResponder, nil); +} @end /* @@ -99,7 +114,6 @@ @interface GormWindowEditor : GormViewWithContentViewEditor { - NSWindow *edited; NSView *edit_view; NSMutableArray *subeditors; BOOL isLinkSource; @@ -112,7 +126,6 @@ - (void) changeFont: (id) sender; - (void) close; - (void) closeSubeditors; -// - (void) copySelection; - (void) deactivate; - (void) deleteSelection; - (id) document; @@ -123,10 +136,6 @@ - (void) orderFront; - (void) pasteInSelection; - (void) resetObject: (id)anObject; -// - (void) selectObjects: (NSArray*)objects; -// - (void) validateEditing; -// - (BOOL) wantsSelection; -// - (NSWindow*) window; @end @implementation GormWindowEditor @@ -165,7 +174,7 @@ contentViewEditor = (GormInternalViewEditor *)[document editorForObject: contentView inEditor: self create: YES]; - [(NSWindow *)_editedObject setInitialFirstResponder: self]; + [_EO setInitialFirstResponder: self]; [self setOpened: YES]; activated = YES; return YES; @@ -192,10 +201,8 @@ } [self closeSubeditors]; - [self deactivate]; - - [document editor: self didCloseForObject: edited]; + [document editor: self didCloseForObject: _EO]; } - (void) closeSubeditors @@ -219,6 +226,7 @@ if (activated == YES) { [contentViewEditor deactivate]; + [_EO unsetInitialFirstResponder]; activated = NO; } return; @@ -229,10 +237,9 @@ if (closed == NO) [self close]; - // RELEASE(edited); RELEASE(selection); RELEASE(subeditors); - // RELEASE(document); + [super dealloc]; } @@ -240,6 +247,20 @@ { } +/* +- (id) retain +{ + NSLog(@"Being retained... %d: %@", [self retainCount], self); + return [super retain]; +} + +- (oneway void) release +{ + NSLog(@"Being released... %d: %@", [self retainCount], self); + [super release]; +} +*/ + /* * Dragging source protocol implementation */ @@ -292,9 +313,8 @@ object: aDocument]; _displaySelection = YES; - _editedObject = (NSView*)anObject; - ASSIGN(edited, anObject); - RETAIN(edited); + ASSIGN(_editedObject, anObject); + // we don't retain the document... document = aDocument; @@ -304,8 +324,6 @@ selection = [NSMutableArray new]; subeditors = [NSMutableArray new]; - [(NSWindow *)_editedObject setInitialFirstResponder: self]; - activated = NO; closed = NO; @@ -349,7 +367,7 @@ - (void) orderFront { - [edited orderFront: self]; + [_EO orderFront: self]; } - (void) pasteInSelection diff --git a/Palettes/0Menus/GormMenuEditor.m b/Palettes/0Menus/GormMenuEditor.m index aa5dfa18..ca5df3bc 100644 --- a/Palettes/0Menus/GormMenuEditor.m +++ b/Palettes/0Menus/GormMenuEditor.m @@ -513,6 +513,7 @@ [self close]; } + RELEASE(edited); RELEASE(selection); RELEASE(subeditor); [super dealloc]; @@ -678,7 +679,6 @@ void _attachAll(NSMenu *menu, id document) { document = aDocument; ASSIGN(edited, anObject); - RETAIN(edited); selection = [NSMutableArray new]; rep = [edited menuRepresentation]; @@ -1076,8 +1076,6 @@ static BOOL done_editing; didDrawBackground = [editField drawsBackground]; [editField setDrawsBackground: YES]; -// [editField display]; - [nc addObserver: self selector: @selector(handleNotification:) name: NSControlTextDidEndEditingNotification diff --git a/Palettes/0Menus/GormNSMenu.m b/Palettes/0Menus/GormNSMenu.m index af97ad3b..9ec8e6d8 100644 --- a/Palettes/0Menus/GormNSMenu.m +++ b/Palettes/0Menus/GormNSMenu.m @@ -107,6 +107,13 @@ [super sendEvent: theEvent]; } + + +- (void) dealloc +{ + // FIXME: This prevents a leak and a crash. + [self _setMenu: nil]; +} @end @implementation GormNSMenu @@ -136,12 +143,32 @@ } #ifdef DEBUG -// This method is purely for debugging purposes... +// These methods are purely for debugging purposes... +/* - (void) display { NSDebugLog(@"In GormNSMenu display..."); [super display]; } + +- (id) retain +{ + NSLog(@"Being retained... %d: %@", [self retainCount], self); + return [super retain]; +} + +- (oneway void) release +{ + NSLog(@"Being released... %d: %@", [self retainCount], self); + [super release]; +} + +- (void) dealloc +{ + NSLog(@"Deallocing %@",self); + [super dealloc]; +} +*/ #endif @end diff --git a/Palettes/1Windows/GormNSPanel.h b/Palettes/1Windows/GormNSPanel.h index 7af45b5f..cebcf5bd 100644 --- a/Palettes/1Windows/GormNSPanel.h +++ b/Palettes/1Windows/GormNSPanel.h @@ -30,9 +30,12 @@ @interface GormNSPanel : NSPanel { unsigned _gormStyleMask; + BOOL _gormReleasedWhenClosed; } - (void) setStyleMask: (unsigned)newStyleMask; - (unsigned) styleMask; +- (void) _setReleasedWhenClosed: (BOOL) flag; +- (BOOL) _isReleasedWhenClosed; @end #endif diff --git a/Palettes/1Windows/GormNSPanel.m b/Palettes/1Windows/GormNSPanel.m index 1b3c74c0..27f613b4 100644 --- a/Palettes/1Windows/GormNSPanel.m +++ b/Palettes/1Windows/GormNSPanel.m @@ -31,10 +31,16 @@ - (void)encodeWithCoder: (NSCoder*) aCoder { unsigned oldStyleMask; + + // save the old values... oldStyleMask = _styleMask; + + // set the values we wish to save.. after save restore. _styleMask = _gormStyleMask; + [self setReleasedWhenClosed: _gormReleasedWhenClosed]; [super encodeWithCoder: aCoder]; _styleMask = oldStyleMask; + [self setReleasedWhenClosed: NO]; } - (id) initWithContentRect: (NSRect)contentRect @@ -65,4 +71,14 @@ { return @"NSPanel"; } + +- (void) _setReleasedWhenClosed: (BOOL) flag +{ + _gormReleasedWhenClosed = flag; +} + +- (BOOL) _isReleasedWhenClosed +{ + return _gormReleasedWhenClosed; +} @end diff --git a/Palettes/1Windows/GormNSWindow.h b/Palettes/1Windows/GormNSWindow.h index a30bb248..85633503 100644 --- a/Palettes/1Windows/GormNSWindow.h +++ b/Palettes/1Windows/GormNSWindow.h @@ -29,9 +29,12 @@ @interface GormNSWindow : NSWindow { unsigned _gormStyleMask; + BOOL _gormReleasedWhenClosed; } - (void) setStyleMask: (unsigned)newStyleMask; - (unsigned) styleMask; +- (void) _setReleasedWhenClosed: (BOOL) flag; +- (BOOL) _isReleasedWhenClosed; @end #endif diff --git a/Palettes/1Windows/GormNSWindow.m b/Palettes/1Windows/GormNSWindow.m index f5f19d67..22068585 100644 --- a/Palettes/1Windows/GormNSWindow.m +++ b/Palettes/1Windows/GormNSWindow.m @@ -28,10 +28,16 @@ - (void) encodeWithCoder: (NSCoder*)aCoder { unsigned oldStyleMask; + + // save the old values... oldStyleMask = _styleMask; + + // set the values we wish to save.. after save restore. _styleMask = _gormStyleMask; + [self setReleasedWhenClosed: _gormReleasedWhenClosed]; [super encodeWithCoder: aCoder]; _styleMask = oldStyleMask; + [self setReleasedWhenClosed: NO]; } - (id) initWithContentRect: (NSRect)contentRect @@ -68,4 +74,35 @@ { return @"NSWindow"; } + +- (void) _setReleasedWhenClosed: (BOOL) flag +{ + _gormReleasedWhenClosed = flag; +} + +- (BOOL) _isReleasedWhenClosed +{ + return _gormReleasedWhenClosed; +} + +// for testing... +/* +- (id) retain +{ + NSLog(@"Being retained... %d: %@", [self retainCount], self); + return [super retain]; +} + +- (oneway void) release +{ + NSLog(@"Being released... %d: %@", [self retainCount], self); + [super release]; +} + +- (void) dealloc +{ + NSLog(@"Deallocing %@",self); + [super dealloc]; +} +*/ @end diff --git a/Palettes/1Windows/main.m b/Palettes/1Windows/main.m index d21aef8f..b27b9b6c 100644 --- a/Palettes/1Windows/main.m +++ b/Palettes/1Windows/main.m @@ -252,7 +252,7 @@ NSwindow inspector // Release When Closed flag = ([[control cellAtRow: 0 column: 0] state] == NSOnState) ? YES : NO; - [object setReleasedWhenClosed: flag]; + [object _setReleasedWhenClosed: flag]; // Hide on deactivate flag = ([[control cellAtRow: 1 column: 0] state] == NSOnState) ? YES : NO; @@ -307,7 +307,7 @@ NSwindow inspector [controlMatrix selectCellAtRow: 2 column: 0]; [optionMatrix deselectAllCells]; - if ([anObject isReleasedWhenClosed]) + if ([anObject _isReleasedWhenClosed]) [optionMatrix selectCellAtRow: 0 column: 0]; if ([anObject hidesOnDeactivate]) [optionMatrix selectCellAtRow: 1 column: 0];