From 7df12d17e5385a2c110e1eca43969603ef66b833 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 11 Aug 2007 12:54:55 -0700 Subject: [PATCH] We previously were leaking all over the place due to improper use of memory management techniques and circular references * English.lproj/Debugger.nib: Setting DebuggerWindowController as the window's delgate * Source/AppDelegate.h: Adding a connections ivar * Source/AppDelegate.m: ([AppDelegate init]): New method to initialize the connections array ([AppDelegate applicationWillTerminate:]): Frees the connections array ([AppDelegate registerConnection:]): New method to register a DebuggerConnection ([AppDelegate unregisterConnection:]): Unregisters a DebuggerConnection * Source/ConnectWindowController.m: ([ConnectWindowController connect:]): We weren't properly release'ing the connection, so now we register it with the delegate and release it in the connect method * Source/DeubggerConnection.h: Added a windowDidClose method so that the window controller can forward the message * Source/DebuggerConnection.m: ([DebuggerConnection windowDidClose]): New method to forward the windowWillClose notification ([DebuggerConnection initWithPort:session:]): We no longer have to register for NSApplicationWillTerminate ([DebuggerConnection applicationWillTerminate:]): Removed ([DebuggerConnection dealloc]): Release _windowController * Source/DebuggerWindowController.m: ([DebuggerWindowController initWithConnection:]): No longer retain the connection as it creates a circular ref ([DebuggerWindowController windowWillClose:]): Use this delegate method to buble the notification to the controller ([DebuggerWindowController dealloc]): Since we don't retain _connection, don't release it * Source/SocketWrapper.m: ([SocketWrapper dealloc]): Remove ourselves as a notification observer so we don't have a nil reference --- English.lproj/Debugger.nib/keyedobjects.nib | Bin 16759 -> 16826 bytes Source/AppDelegate.h | 10 ++++-- Source/AppDelegate.m | 36 ++++++++++++++++++++ Source/ConnectWindowController.m | 5 ++- Source/DebuggerConnection.h | 2 ++ Source/DebuggerConnection.m | 15 ++++---- Source/DebuggerWindowController.m | 12 +++++-- Source/SocketWrapper.m | 1 + 8 files changed, 67 insertions(+), 14 deletions(-) diff --git a/English.lproj/Debugger.nib/keyedobjects.nib b/English.lproj/Debugger.nib/keyedobjects.nib index c3914bb0668c83d8530cc6d28128afbce6335f52..4da3cc61873392b8ec73848edff28a25b4ea58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m18b?|lb_4XC{#`u!H z*}e+ja^Fecx4zT9?|nb`⁣zF8F@(UGZJ_-SXY_{o;Gzd*plSdqIjwjFgaaQblS= zJ!vAXq=O_#nruwABy-44WM{G~*^TU*B!`lP z{*(Sk0b?K$XcOoi7#bKIC=ZMYj19aQ7#EljNCvpTq`<7elEAXSia_%1z^cHSz}mq2 zKy_eO;KRVdz~_Mrfh&P)fqQ|6K_n;*I)Y3vE7&zSFgPq&92^szAKVh$7Tgis8Qc|o zKe#7&I(RntAfyW!LgtVy22pztH&5#1J2v5}F>G8JZP(Cv+%uK6Ej3Idm;_ zGjuz2H>?f^!u68j2H{5GtZ;U?O}JOMPq=@0V0du2Fq{nY;VI#1;ThpY;SJ$U;p*_# z@b>VY@X_$G@R#AQ!~Y3i4nGV(3O@}$k023qq)wz>Bs0=Dk{xLlX%QJ7;Ukri?U5ak z_aeI@yCZudA4c{^4n__~jz_+UoQ|A{oQ<4|T#MX}B%ef)s3bOu z9g^{m@z>*h;)U^%@zQu%ygWWLzAU~XzB0Z#UKQUF-y8oW{%ibU{89W#{8{`3g;Hr0 zMu{mYC8v~>n$l1@%0QVY3uU96l#B9EKFUu8sW26z>Qb3hb7}&Wq7PXREO;u6rs14L6>K$qewT;?A?WA^7`>EU1UFsfnpL#(3 zMm?sUQqO7O?LpqvIwyK2 zh9rs-BNL^G@reluE-^FlIPo;`oIx4Dh#489U{nmwXc;|YWXz0>aWDkqX1t7_2{K_O z%1}&#NoO*c`boK>+JR?nJPE9+ogte5q(AvVfVEW_4e>#><^ zV>X*@&c4RBVcWAE+0JY(+k@@R_G1UKdF(Lu4YrUS$(FLC*|F?+Hpxy(U2S4Wu3^`* z>)DO$X11E$%5G=hW#40Wv;SiEvLCYlW7_5c6? diff --git a/Source/AppDelegate.h b/Source/AppDelegate.h index 338f8ba..29eafb7 100644 --- a/Source/AppDelegate.h +++ b/Source/AppDelegate.h @@ -15,10 +15,16 @@ */ #import - +#import "DebuggerConnection.h" @interface AppDelegate : NSObject -{} +{ + NSMutableArray *connections; +} + + +- (void)registerConnection: (DebuggerConnection *)cnx; +- (void)unregisterConnection: (DebuggerConnection *)cnx; - (IBAction)showConnectionWindow: (id)sender; diff --git a/Source/AppDelegate.m b/Source/AppDelegate.m index 2be8057..668ab00 100644 --- a/Source/AppDelegate.m +++ b/Source/AppDelegate.m @@ -19,6 +19,26 @@ @implementation AppDelegate +/** + * Initializes + */ +- (id)init +{ + if (self = [super init]) + { + connections = [[NSMutableArray alloc] init]; + } + return self; +} + +/** + * Called when the application is going to go away + */ +- (void)applicationWillTerminate: (NSNotification *)aNotification +{ + [connections release]; +} + /** * When the application has finished loading, show the connection dialog */ @@ -27,6 +47,22 @@ [self showConnectionWindow: self]; } +/** + * Adds an object to the connections array + */ +- (void)registerConnection: (DebuggerConnection *)cnx +{ + [connections addObject: cnx]; +} + +/** + * Removes a given connection from the connections array + */ +- (void)unregisterConnection: (DebuggerConnection *)cnx +{ + [connections removeObject: cnx]; +} + /** * Shows the connection window */ diff --git a/Source/ConnectWindowController.m b/Source/ConnectWindowController.m index dfa93c4..872b398 100644 --- a/Source/ConnectWindowController.m +++ b/Source/ConnectWindowController.m @@ -16,6 +16,7 @@ #import "ConnectWindowController.h" #import "DebuggerConnection.h" +#import "AppDelegate.h" @implementation ConnectWindowController @@ -52,7 +53,9 @@ */ - (IBAction)connect: (id)sender { - [[DebuggerConnection alloc] initWithPort: [_port intValue] session: [_session stringValue]]; + DebuggerConnection *cnx = [[DebuggerConnection alloc] initWithPort: [_port intValue] session: [_session stringValue]]; + [[NSApp delegate] registerConnection: cnx]; + [cnx release]; [[self window] orderOut: self]; } diff --git a/Source/DebuggerConnection.h b/Source/DebuggerConnection.h index 7d848ef..1a31084 100644 --- a/Source/DebuggerConnection.h +++ b/Source/DebuggerConnection.h @@ -34,6 +34,8 @@ // initializer - (id)initWithPort: (int)port session: (NSString *)session; +- (void)windowDidClose; + // getter - (int)port; - (NSString *)session; diff --git a/Source/DebuggerConnection.m b/Source/DebuggerConnection.m index a8cd955..b6d5f4d 100644 --- a/Source/DebuggerConnection.m +++ b/Source/DebuggerConnection.m @@ -15,6 +15,7 @@ */ #import "DebuggerConnection.h" +#import "AppDelegate.h" @interface DebuggerConnection (Private) @@ -44,22 +45,17 @@ [_socket setDelegate: self]; [_windowController setStatus: @"Connecting"]; [_socket connect]; - - // clean up after ourselves - [[NSNotificationCenter defaultCenter] addObserver: self - selector: @selector(applicationWillTerminate:) - name: NSApplicationWillTerminateNotification - object: NSApp]; } return self; } /** - * Release ourselves when we're about to die + * This is a forwarded message from DebuggerWindowController that tells the connection to prepare to + * close */ -- (void)applicationWillTerminate: (NSNotification *)notif +- (void)windowDidClose { - [self release]; + [[NSApp delegate] unregisterConnection: self]; } /** @@ -69,6 +65,7 @@ { [_session release]; [_socket release]; + [_windowController release]; [super dealloc]; } diff --git a/Source/DebuggerWindowController.m b/Source/DebuggerWindowController.m index f0483e4..08a9529 100644 --- a/Source/DebuggerWindowController.m +++ b/Source/DebuggerWindowController.m @@ -17,6 +17,7 @@ #import "DebuggerWindowController.h" #import "DebuggerConnection.h" #import "NSXMLElementAdditions.h" +#import "AppDelegate.h" @interface DebuggerWindowController (Private) @@ -33,7 +34,7 @@ { if (self = [super initWithWindowNibName: @"Debugger"]) { - _connection = [cnx retain]; + _connection = cnx; _expandedRegisters = [[NSMutableArray alloc] init]; } return self; @@ -53,12 +54,19 @@ [_sourceViewerScroller display]; } +/** + * Called when the window is going to be closed so we can clean up all of our stuff + */ +- (void)windowWillClose: (NSNotification *)aNotification +{ + [_connection windowDidClose]; +} + /** * Release object members */ - (void)dealloc { - [_connection release]; [_expandedRegisters release]; [super dealloc]; diff --git a/Source/SocketWrapper.m b/Source/SocketWrapper.m index 91c8b32..80dc779 100644 --- a/Source/SocketWrapper.m +++ b/Source/SocketWrapper.m @@ -60,6 +60,7 @@ NSString *NsockDataSent = @"SocketWrapper_DataSent"; */ - (void)dealloc { + [[NSNotificationCenter defaultCenter] removeObserver: self]; close(_socket); [super dealloc]; -- 2.43.5