Re: ARC Release too soon
On 16 Mar 2013, at 21:52, Kevin Muldoon wrote: I'd think adding the WindowController to a @property (strong, nonatomic) NSArray *array; would keep those objects alive. Most often, I would simply add each WindowController (or in my case, ViewController) one-at-a-time in the .h. I simply feel it's clearer to see. @property (strong, nonatomic) RJLarryViewController *larryViewController; @property (strong, nonatomic) RJCurleyViewController *curleyViewController; @property (strong, nonatomic) RJMoeViewController *moeViewController; Yeah, but since he isn't tracking the closing (disposing) of the window's, he can't then release the reference, so it will leak. Probably the best way I can think of to do it elegantly, would be to write a wrapper manager class around the window's which tracks when they are to be disposed of and removes the corresponding entry is a dictionary or array. One thing you can do is to convert the Object pointer to a hex string and use this as a key into a dictionary. Then just check if *that* window object is being disposed of and is in the dict, remove it. e.g. obj*myObj; myObjKey = [[NSStriing alloc] initWithFormat:@"%p",myObj]; When you create a new window, do something like this: [WRAPPERCLASS addWindow:myWindow]; addWindow:myWindow, adds it to the dict and sets a monitor for it closing. One thing that puzzles me is, in the non ARC build, don't you get an Analyzer Warnings on this? Cheers Dave On Mar 16, 2013, at 5:38 PM, Chris Paveglio wrote: Sure I totally understand that. My question is more of "what is the most elegant way to do it". Add them to an array? - Original Message - From: iain To: Chris Paveglio Cc: Cocoa Dev List Sent: Saturday, March 16, 2013 2:35 PM Subject: Re: ARC Release too soon On 16 Mar 2013, at 06:16 PM, Chris Paveglio wrote: So, am I doing some fundamental window management wrong (not sure since old app worked OK and didn't seem to leak), or how do I do something so ARC doesn't dealloc window controllers at the end of the function that fires them off If you want the window controllers to hang around after the function finished you need to assign them to a strong variable otherwise they will be released. Iain ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/caoimghgin% 40gmail.com This email sent to caoimgh...@gmail.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/dave% 40looktowindward.com This email sent to d...@looktowindward.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: ARC Release too soon
If it's for windows where the number of them is under user control, then I typically add them to a an array (which is a strongly retained property) then you can either listen for window closing notifications and remove them, or if the user may open the same window again, then you can check the array before creating a new controller. If the controller for that window exists, then you can just reshow it. I use this pattern a lot, so it was easy for me to find an example: - (void) showEditorForItem:(id)item { // check if we have an editor array already if (self.editorControllers == nil) { self.editorControllers = [NSMutableArray array]; } BOOL foundController = NO; for (EditorController *editor in self.editorControllers) { if (editor.item == item) { [editor showWindow:self]; foundController = YES; break; } } if (foundController == NO) { EditorController *editor = [[EditorController alloc] initWithItem:item managedObjectContext:self.managedObjectContext]; [editor showWindow:self]; [self.editorControllers addObject:editor]; } } - Martin On 16, Mar, 2013, at 10:38 PM, Chris Paveglio wrote: > Sure I totally understand that. My question is more of "what is the most > elegant way to do it". Add them to an array? > > > - Original Message - > From: iain > To: Chris Paveglio > Cc: Cocoa Dev List > Sent: Saturday, March 16, 2013 2:35 PM > Subject: Re: ARC Release too soon > > > > On 16 Mar 2013, at 06:16 PM, Chris Paveglio wrote: > >> So, am I doing some fundamental window management wrong (not sure since old >> app worked OK and didn't seem to leak), or how do I do something so ARC >> doesn't dealloc window controllers at the end of the function that fires >> them off > > If you want the window controllers to hang around after the function finished > you need to assign them to a strong variable otherwise they will be released. > > Iain > ___ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > Please do not post admin requests or moderator comments to the list. > Contact the moderators at cocoa-dev-admins(at)lists.apple.com > > Help/Unsubscribe/Update your Subscription: > https://lists.apple.com/mailman/options/cocoa-dev/martin.hewitson%40aei.mpg.de > > This email sent to martin.hewit...@aei.mpg.de ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: ARC Release too soon
I'd think adding the WindowController to a @property (strong, nonatomic) NSArray *array; would keep those objects alive. Most often, I would simply add each WindowController (or in my case, ViewController) one-at-a-time in the .h. I simply feel it's clearer to see. @property (strong, nonatomic) RJLarryViewController *larryViewController; @property (strong, nonatomic) RJCurleyViewController *curleyViewController; @property (strong, nonatomic) RJMoeViewController *moeViewController; On Mar 16, 2013, at 5:38 PM, Chris Paveglio wrote: > Sure I totally understand that. My question is more of "what is the most > elegant way to do it". Add them to an array? > > > - Original Message - > From: iain > To: Chris Paveglio > Cc: Cocoa Dev List > Sent: Saturday, March 16, 2013 2:35 PM > Subject: Re: ARC Release too soon > > > > On 16 Mar 2013, at 06:16 PM, Chris Paveglio wrote: > >> So, am I doing some fundamental window management wrong (not sure since old >> app worked OK and didn't seem to leak), or how do I do something so ARC >> doesn't dealloc window controllers at the end of the function that fires >> them off > > If you want the window controllers to hang around after the function finished > you need to assign them to a strong variable otherwise they will be released. > > Iain > ___ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > Please do not post admin requests or moderator comments to the list. > Contact the moderators at cocoa-dev-admins(at)lists.apple.com > > Help/Unsubscribe/Update your Subscription: > https://lists.apple.com/mailman/options/cocoa-dev/caoimghgin%40gmail.com > > This email sent to caoimgh...@gmail.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: ARC Release too soon
Sure I totally understand that. My question is more of "what is the most elegant way to do it". Add them to an array? - Original Message - From: iain To: Chris Paveglio Cc: Cocoa Dev List Sent: Saturday, March 16, 2013 2:35 PM Subject: Re: ARC Release too soon On 16 Mar 2013, at 06:16 PM, Chris Paveglio wrote: > So, am I doing some fundamental window management wrong (not sure since old > app worked OK and didn't seem to leak), or how do I do something so ARC > doesn't dealloc window controllers at the end of the function that fires them > off If you want the window controllers to hang around after the function finished you need to assign them to a strong variable otherwise they will be released. Iain ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: ARC Release too soon
On 16 Mar 2013, at 06:16 PM, Chris Paveglio wrote: > So, am I doing some fundamental window management wrong (not sure since old > app worked OK and didn't seem to leak), or how do I do something so ARC > doesn't dealloc window controllers at the end of the function that fires them > off If you want the window controllers to hang around after the function finished you need to assign them to a strong variable otherwise they will be released. Iain ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
ARC Release too soon
I'm working with ARC for the first time just now. I'm running into an issue where ARC is releasing objects too soon and I am not sure the best way to fix it. Under GC it works correctly, even in the same project if I turn off ARC and turn GC back on. I have an AppDelegate that will spawn any number of windows. In the primary window, the user enters some fields, then presses the button that generates a new window (one of 2 different classes depending on input). The new window controller is initialized and then the values are passed to the new window controller which does the real work. But I don't have any method in the AppDelegate to keep track of the spawned windows. There is not really any reason to IMO, because they never reference anything back to the initial window. I am not declaring an app-wide variable in AppDelegate for any window controllers, nor putting the new window controllers into an array or anything. The new window data can't be saved, it's display once and done (I am not using a normal document-based application template). So, am I doing some fundamental window management wrong (not sure since old app worked OK and didn't seem to leak), or how do I do something so ARC doesn't dealloc window controllers at the end of the function that fires them off? Thanks, Chris ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com