Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-05-2011, 08:08 AM   #1 (permalink)
Developer of Phranslator
 
Join Date: Mar 2010
Posts: 8
alexeyndru is on a distinguished road
Default Property gets released in a strange manner

I have a property in the app delegate which is a NSMutableArray. I store there some results I get from the web. The problem is that the second time I try to set this property (I call the setter from another class) I get EXC_BAD_ACCESS. Just right when I step into "synthesize". I solved the problem by retaining this property. I would like to understand why this property gets released since it's in the app-delegate class. What is happening to it when I try to set it the second time? Thanks.

Bellow in the code: when I get back in the current view controller to make another search, when it gets to setting locArray I get EXC_BAD_ACCESS unless I retain locArray. So, what could happen to the property which belongs to app delegate? Why do I need to retain it?


[(RedAppDelegate *)[[UIApplication sharedApplication] delegate] setLocArray:foundLocations];
[[(RedAppDelegate *)[[UIApplication sharedApplication] delegate] locArray] retain];


RezViewController *aRez = [[RezViewController alloc] init];
[self.navigationController pushViewController:aRez animated:YES];
[aRez release];

Last edited by alexeyndru; 01-05-2011 at 08:21 AM. Reason: to add some code
alexeyndru is offline   Reply With Quote
Old 01-05-2011, 08:09 AM   #2 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Do you really expect to get an answer without posting any code?
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 01-05-2011, 08:23 AM   #3 (permalink)
Developer of Phranslator
 
Join Date: Mar 2010
Posts: 8
alexeyndru is on a distinguished road
Default Here's the code. Thanks for helping !

Quote:
Originally Posted by BrianSlick View Post
Do you really expect to get an answer without posting any code?
[(RedAppDelegate *)[[UIApplication sharedApplication] delegate] setLocArray:foundLocations];
[[(RedAppDelegate *)[[UIApplication sharedApplication] delegate] locArray] retain];


RezViewController *aRez = [[RezViewController alloc] init];
[self.navigationController pushViewController:aRez animated:YES];
[aRez release];
alexeyndru is offline   Reply With Quote
Old 01-05-2011, 08:30 AM   #4 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

The view controller stuff is not relevant. You need to post more about locArray. How is it declared in the .h file? And you need to post more about foundLocations. Use your head and provide useful code if you want a solution.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 01-05-2011, 08:49 AM   #5 (permalink)
Developer of Phranslator
 
Join Date: Mar 2010
Posts: 8
alexeyndru is on a distinguished road
Default

Quote:
Originally Posted by BrianSlick View Post
The view controller stuff is not relevant. You need to post more about locArray. How is it declared in the .h file? And you need to post more about foundLocations. Use your head and provide useful code if you want a solution.
-locArray is a NSMutableArray declared in app-delegate;
-foundLocations is a NSMutableArray initialized with data from a remote database and it is declared as a property in the current view controller;

The app I am working makes use of maps. I let the user search locations and the results I put first in foundLocations and then in locArray (which sits in app - delegate as I mentioned before). Now everythings work fine after I retained locArray (it was just a guess), but I want to understand what is going on with that property which is initialized in app-did-launch. Why it works when the first search is performed and why I need retain it in order to be able to use it the next time I search.
alexeyndru is offline   Reply With Quote
Old 01-05-2011, 08:53 AM   #6 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

How many more times am I going to have to ask for code before you will actually show it? What your app does is completely useless information. You get one more chance to post relevant code before I'm done with this thread. Don't describe or summarize anything else. Copy. Paste. Code.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 01-05-2011, 09:14 AM   #7 (permalink)
Developer of Phranslator
 
Join Date: Mar 2010
Posts: 8
alexeyndru is on a distinguished road
Default

Quote:
Originally Posted by BrianSlick View Post
How many more times am I going to have to ask for code before you will actually show it? What your app does is completely useless information. You get one more chance to post relevant code before I'm done with this thread. Don't describe or summarize anything else. Copy. Paste. Code.
Ok, I am too noob for a conversation with you. I just don't know what would be more relevant than what I have already shown. Thank you for your help and have a nice day.
alexeyndru is offline   Reply With Quote
Old 01-05-2011, 09:25 AM   #8 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Ok look. There are only two possibilities here. Either you have made a mistake, or you misunderstand something. The only way we are going to figure that out is to see what you have actually done.

You have not shown how your property is declared. This would be the relevant lines from your .h file.

You have not shown how this other array is created or destroyed. This would be the code before and possibly after what you posted previously.

You are expecting me to assume that your verbal descriptions indicate that things were done correctly. If they were done correctly, then you wouldn't have a problem, so this is a bad assumption. And if you don't even know what code to show in order to solve the problem, then I have no reason to assume that you know what you're doing. So, show what you are doing.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Reply

Bookmarks

Tags
application delegate, exc_bad_access, nsmutablearray, retain

Thread Tools
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
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 357
7 members and 350 guests
blueorb, fredidf, iAppDeveloper, iGamesDev, mottdog, sacha1996, Touchmint
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,667
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, host number one
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:31 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0