NSLog object = nil?
Dear list, I have the following structure: An itemStore object creates a worker object (property of itemStore object) that hold a weak reference back to the itemStore object; When the worker classes is done, it sets the itemStore object (of which the worker class itself is a property) to nil. This project uses ARC. So within itemStore I do: self.worker = [[Worker alloc] init]; [self.worker setItemStore:self]; In Worker.h I do @property (nonatomic, weak) ItemStore *itemStore; In Worker.m, when all its tasks are done, I do self.itemStore = nil; I assume this completely destroys the itemStore object and all objects it exclusively owns. Is there any way to NSLog the destruction of the itemStore object? I tried putting a log in itemStore's dealloc method, but it doesn't show up in the console. Many thanks, Diederik ___ 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: NSLog object = nil?
On 20 Aug 2013, at 23:32, Diederik Meijer | Ten Horses diede...@tenhorses.com wrote: Dear list, I have the following structure: An itemStore object creates a worker object (property of itemStore object) that hold a weak reference back to the itemStore object; When the worker classes is done, it sets the itemStore object (of which the worker class itself is a property) to nil. This project uses ARC. So within itemStore I do: self.worker = [[Worker alloc] init]; [self.worker setItemStore:self]; In Worker.h I do @property (nonatomic, weak) ItemStore *itemStore; In Worker.m, when all its tasks are done, I do self.itemStore = nil; I assume this completely destroys the itemStore object and all objects it exclusively owns. Is there any way to NSLog the destruction of the itemStore object? I tried putting a log in itemStore's dealloc method, but it doesn't show up in the console. No, this doesn’t destroy the item store at all. If the Worker holds a weak reference, then it setting its reference to nil will not do anything at all re memory management. Instead, whatever is holding strong references to the item store needs to release those references. Tom Davie ___ 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: NSLog object = nil?
On Aug 20, 2013, at 4:32 PM, Diederik Meijer | Ten Horses wrote: An itemStore object creates a worker object (property of itemStore object) that hold a weak reference back to the itemStore object; When the worker classes is done, it sets the itemStore object (of which the worker class itself is a property) to nil. It doesn't set the object to nil. It sets its reference to the itemStore object to nil. This project uses ARC. So within itemStore I do: self.worker = [[Worker alloc] init]; [self.worker setItemStore:self]; In Worker.h I do @property (nonatomic, weak) ItemStore *itemStore; In Worker.m, when all its tasks are done, I do self.itemStore = nil; I assume this completely destroys the itemStore object and all objects it exclusively owns. No. The itemStore property of Worker is weak. That means it does not influence the lifetime of the itemStore object it references. Setting the reference to nil simply makes it no longer reference that object. Is there any way to NSLog the destruction of the itemStore object? I tried putting a log in itemStore's dealloc method, but it doesn't show up in the console. Putting a call to NSLog() in the -dealloc would be the way to detect it. Nothing is showing up because the itemStore object is not being deallocated. If you want to deallocate it, you have to make sure to clear all strong references to it. Clearing weak references doesn't help. Regards, Ken ___ 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: NSLog object = nil?
Apologies, no need to respond, I have just fixed this.. Op Aug 20, 2013, om 11:32 PM heeft Diederik Meijer | Ten Horses diede...@tenhorses.com het volgende geschreven: Dear list, I have the following structure: An itemStore object creates a worker object (property of itemStore object) that hold a weak reference back to the itemStore object; When the worker classes is done, it sets the itemStore object (of which the worker class itself is a property) to nil. This project uses ARC. So within itemStore I do: self.worker = [[Worker alloc] init]; [self.worker setItemStore:self]; In Worker.h I do @property (nonatomic, weak) ItemStore *itemStore; In Worker.m, when all its tasks are done, I do self.itemStore = nil; I assume this completely destroys the itemStore object and all objects it exclusively owns. Is there any way to NSLog the destruction of the itemStore object? I tried putting a log in itemStore's dealloc method, but it doesn't show up in the console. Many thanks, Diederik ___ 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/diederik%40tenhorses.com This email sent to diede...@tenhorses.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: NSLog object = nil?
On Aug 20, 2013, at 2:32 PM, Diederik Meijer | Ten Horses wrote: Is there any way to NSLog the destruction of the itemStore object? Sure, but you'll save a lot more time if you use Instruments to track object lifetimes - it'll show you who does own the object and keeps you from hitting dealloc. ___ 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: NSLog object = nil?
Wouldn’t be possible to implement dealloc in that class and put an NSLog call there? Of course, in an ARC project, you wouldn’t call [super dealloc] but would that cause a problem? -Laurent. -- Laurent Daudelin AIM/iChat/Skype:LaurentDaudelin http://www.nemesys-soft.com/ Logiciels Nemesys Software laur...@nemesys-soft.com On Aug 20, 2013, at 17:45, Ken Thomases k...@codeweavers.com wrote: On Aug 20, 2013, at 4:32 PM, Diederik Meijer | Ten Horses wrote: An itemStore object creates a worker object (property of itemStore object) that hold a weak reference back to the itemStore object; When the worker classes is done, it sets the itemStore object (of which the worker class itself is a property) to nil. It doesn't set the object to nil. It sets its reference to the itemStore object to nil. This project uses ARC. So within itemStore I do: self.worker = [[Worker alloc] init]; [self.worker setItemStore:self]; In Worker.h I do @property (nonatomic, weak) ItemStore *itemStore; In Worker.m, when all its tasks are done, I do self.itemStore = nil; I assume this completely destroys the itemStore object and all objects it exclusively owns. No. The itemStore property of Worker is weak. That means it does not influence the lifetime of the itemStore object it references. Setting the reference to nil simply makes it no longer reference that object. Is there any way to NSLog the destruction of the itemStore object? I tried putting a log in itemStore's dealloc method, but it doesn't show up in the console. Putting a call to NSLog() in the -dealloc would be the way to detect it. Nothing is showing up because the itemStore object is not being deallocated. If you want to deallocate it, you have to make sure to clear all strong references to it. Clearing weak references doesn't help. Regards, Ken ___ 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/laurent%40nemesys-soft.com This email sent to laur...@nemesys-soft.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: NSLog object = nil?
Thanks for this. I'd like to try using the Document object that owns the itemStore. The itemStore objects are created by the Document object in a loop as part of a dispatch_async GCD block. The itemStores' workers have a reference to the Document object. But since the itemStore objects are created within a loop and not as properties, the Document object has no direct reference to them. This means that calling self.document.itemStore = nil won't help either. Or is there a way to do this? I'd like to clear out itemStores for which the workers have completed their tasks, to manage CPU usage... Verstuurd vanaf mijn iPhone Op 20 aug. 2013 om 23:45 heeft Ken Thomases k...@codeweavers.com het volgende geschreven: On Aug 20, 2013, at 4:32 PM, Diederik Meijer | Ten Horses wrote: An itemStore object creates a worker object (property of itemStore object) that hold a weak reference back to the itemStore object; When the worker classes is done, it sets the itemStore object (of which the worker class itself is a property) to nil. It doesn't set the object to nil. It sets its reference to the itemStore object to nil. This project uses ARC. So within itemStore I do: self.worker = [[Worker alloc] init]; [self.worker setItemStore:self]; In Worker.h I do @property (nonatomic, weak) ItemStore *itemStore; In Worker.m, when all its tasks are done, I do self.itemStore = nil; I assume this completely destroys the itemStore object and all objects it exclusively owns. No. The itemStore property of Worker is weak. That means it does not influence the lifetime of the itemStore object it references. Setting the reference to nil simply makes it no longer reference that object. Is there any way to NSLog the destruction of the itemStore object? I tried putting a log in itemStore's dealloc method, but it doesn't show up in the console. Putting a call to NSLog() in the -dealloc would be the way to detect it. Nothing is showing up because the itemStore object is not being deallocated. If you want to deallocate it, you have to make sure to clear all strong references to it. Clearing weak references doesn't help. Regards, Ken ___ 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