Re: releasing an object
Re: releasing an object
- Subject: Re: releasing an object
- From: Nick Rogers <email@hidden>
- Date: Sat, 10 Oct 2009 21:13:38 +0530
Hi, Thanks for the reply.
In AppController.h I have an ivar:
Volume *selectedPTVolume;
In a method in AppController, I have the following:
NSMutableDictionary *data = [partitionListDictArray objectAtIndex:
[tableViewPTList selectedRow]];
selectedPTVolume = [[Volume alloc] initWithDictionary:data];
[selectedPTVolume retain];// if I comment this the GUI hangs,
selectedPTVolume contains an ivar HDIR *dirRoot; which is passed as
the root item of an outline view. dirRoot has an mutable array, which
contains other HDIR objects as its children and so on a tree is formed.
In a method, where I need to release selectedPTVolume, I have:
if (selectedPTVolume)
{
volumeScanType = [selectedPTVolume volumeScanType];//
selectedPTVolume retainCount = 2 here
[selectedPTVolume release];
[selectedPTVolume release];// selectedPTVolume retainCount = 1 here
selectedPTVolume = nil;// selectedPTVolume retainCount = 0 here and
sometimes still shows as 1 while debugging.
if (outlineViewData)
[outlineViewData reloadData];/ crashes here
}
Releasing selectedPTVolume also releases HDIR *dirRoot.
Wishes,
Nick
On 10-Oct-2009, at 4:06 PM, Graham Cox wrote:
On 10/10/2009, at 9:31 PM, Nick Rogers wrote:
Shall I get its retainCount and then release it that many times?
For heavens' sake, NO!
Ignore retain counts. They are not reliable evidence of anything you
can use. Instead, just follow the rules:
http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmRules.html
I'm doing alloc and initWithDictionary to get an instance of Volume.
I have to do [selectedPTVolume retain]; when allocing to get it to
work properly.
Show your code. This sounds wrong, but without seeing the code it
can't really be inferred from the description.
--Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden