Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jul 4, 2008, 02:05 AM   #1
sujithkrishnan
macrumors 6502
 
Join Date: May 2008
Location: Bangalore
Send a message via Yahoo to sujithkrishnan
releasing Objects [iPhone]

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...
sujithkrishnan is offline   0 Reply With Quote
Old Jul 4, 2008, 02:43 AM   #2
HiRez
macrumors 68040
 
HiRez's Avatar
 
Join Date: Jan 2004
Location: 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.
__________________
Go outside, the graphics are amazing!
HiRez is offline   0 Reply With Quote
Old Jul 4, 2008, 03:30 AM   #3
sujithkrishnan
Thread Starter
macrumors 6502
 
Join Date: May 2008
Location: Bangalore
Send a message via Yahoo to sujithkrishnan
Quote:
Originally Posted by HiRez View Post
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];
}
sujithkrishnan is offline   0 Reply With Quote
Old Jul 4, 2008, 04:28 AM   #4
HiRez
macrumors 68040
 
HiRez's Avatar
 
Join Date: Jan 2004
Location: Western US
Quote:
Originally Posted by sujithkrishnan View Post
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?
__________________
Go outside, the graphics are amazing!
HiRez is offline   0 Reply With Quote
Old Jul 4, 2008, 04:53 AM   #5
sujithkrishnan
Thread Starter
macrumors 6502
 
Join Date: May 2008
Location: Bangalore
Send a message via Yahoo to sujithkrishnan
Quote:
Originally Posted by HiRez View Post
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...)
sujithkrishnan is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Who will release the iPhone 5: Steve Jobs or Tim Cook? pchipchip iPhone 65 Sep 25, 2011 05:17 PM
Ice Cubus - released for iPhone/IPod touch quazarteam iPhone and iPod touch Apps 1 Feb 22, 2011 04:35 AM
Resolved: Quick release of objects carlosbutler iPhone/iPad Programming 3 Feb 13, 2011 06:56 AM
When to release object and vars from memory XcodeNewb iPhone/iPad Programming 8 Feb 15, 2009 09:24 PM


All times are GMT -5. The time now is 03:34 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

Privacy / DMCA contact / Affiliate and FTC Disclosure
Copyright 2002-2013, MacRumors.com, LLC