Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

sujithkrishnan

macrumors 6502
Original poster
May 9, 2008
265
0
Bangalore
Hi all.


In my app i am populating an object (myCatalogObject)through unarchiving....

At the end,when i call release to that object, its calling the dealloc. (its OK)

the dealloc is like below

Code:
(void*) dealloc
{
  [myMutableDictionary release];
  [myMutableArray release];
}

But its giving "EXEC_BAD_ACCESS" for the first line in dealloc method....

I populate the myCatalogObject like below

Code:
Catalog* myCatalogObject = [NSUnarchiver unarchive.......];

The unarchiving is doing perfectly, but i want to relase the memory occuped by object before quitting application...


the Catalog class contains a MutableDictionary and MutableArray.....


Thanks...
 

HiRez

macrumors 603
Jan 6, 2004
6,253
2,579
Western US
First of all, why are you using that C-style format for an Objective-C dealloc method? For example, the dash marking it as an instance method. Looks odd to me. Also, you should be calling super in your dealloc method. I would have something more like this:

Code:
- (void)dealloc {
	[myMutableDictionary release];
	[myMutableArray release];
	[super dealloc];
}

Did you hold onto the myMutableDictionary and myMutableArray objects when you unarchived them by sending them retain messages? If not, they're probably invalid when you try to release them, leading to the EXEC_BAD_ACCESS error.
 

sujithkrishnan

macrumors 6502
Original poster
May 9, 2008
265
0
Bangalore
First of all, why are you using that C-style format for an Objective-C dealloc method? For example, the dash marking it as an instance method. Looks odd to me. Also, you should be calling super in your dealloc method. I would have something more like this:

Code:
- (void)dealloc {
	[myMutableDictionary release];
	[myMutableArray release];
	[super dealloc];
}

Did you hold onto the myMutableDictionary and myMutableArray objects when you unarchived them by sending them retain messages? If not, they're probably invalid when you try to release them, leading to the EXEC_BAD_ACCESS error.

I didnt get how to retain the myMutableDictionary and myMutableArray, explicitly....

I am just unarchiving the entire object...

Did u mean ... after archiving, i want to call retain to both of them?

my dealloc is like below only (what u mentioned)
Code:
- (void)dealloc {
	[myMutableDictionary release];
	[myMutableArray release];
	[super dealloc];
}
 

HiRez

macrumors 603
Jan 6, 2004
6,253
2,579
Western US
I am just unarchiving the entire object...

Did u mean ... after archiving, i want to call retain to both of them?
Oh, I see, you are archiving the entire object graph at once. Well, you still need to retain that myCatalogObject after you unarchive it, which means you need to release it at some point. Are you releasing that object as well in the dealloc: method of whatever class it belongs to (like your application controller maybe)? In other words, do you have the line [myCatalogObject release]; anywhere? Is that dealloc: method you listed the dealloc: for the Catalog class, or something else?
 

sujithkrishnan

macrumors 6502
Original poster
May 9, 2008
265
0
Bangalore
Oh, I see, you are archiving the entire object graph at once. Well, you still need to retain that myCatalogObject after you unarchive it, which means you need to release it at some point. Are you releasing that object as well in the dealloc: method of whatever class it belongs to (like your application controller maybe)? In other words, do you have the line [myCatalogObject release]; anywhere? Is that dealloc: method you listed the dealloc: for the Catalog class, or something else?

Yeah..
i am calling the "[myCatalogObject release]" in my viewController, in turn that release calling the "dealloc" of Catalog (class of myCatalogObject) ...
(dellaoc is calling as retainCount is 0, isnt it...thats what i want...)
but in the "dealoc" of Catalog i release the dictionary and array, i got error when i call these two lines....

Do i want to retain myCatalogObject or dictionary & array ????

But if i call retain for myCatalogObject, retainCount of that while application terminating is "1", instead it is zero now (which is fine and apt...)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.