Hello,
I have an array created through dataaccess and parsing when my app starts to run. This array is then available in my appDelegate. Each viewcontroller who needs access to this data saved in the array are calling it using:
The object theList is where my confusion starts. I have tried some different approaches here in order to both get a proper memory management and also to let the object live as long as needed in the app.
So for instance, if I have three table views and the user may navigate between them using a navigationController. Those tables are filled with data as described above. theList is defined as follows:
.h file
NSArray *theList;
.m file
Some things I do not understand here:
If i release theList after the code above, the app is crashing. As I defined it with the property copy I thought I have to release it when I do not want to use it anymore? theList is a pointer to an NSArray object - ie an object that will not change as long as the app lives. I defined it as copy, as I wrote above, because after analyzing the memory use, this seemed to be the most effective solution. I might be wrong...?
Anyway, after copying the objects from theList into an local mutable array, I thought it would be correct to kill theList...? Why is this wrong? The problem I noticed was when navigating between the different tableViews. The app crashed when I revisited a table, and that problem does not appear with the solution above. The question is only - is this the right way to go? Is it effective? Is it robust? The more I read about memory management on iphone development, the lmore confused I feel.
Thanks in advance for any ideas or comments!
MACloop
I have an array created through dataaccess and parsing when my app starts to run. This array is then available in my appDelegate. Each viewcontroller who needs access to this data saved in the array are calling it using:
Code:
theList = [(AppDelegate*)[[UIApplication sharedApplication] delegate] theList];
The object theList is where my confusion starts. I have tried some different approaches here in order to both get a proper memory management and also to let the object live as long as needed in the app.
So for instance, if I have three table views and the user may navigate between them using a navigationController. Those tables are filled with data as described above. theList is defined as follows:
.h file
NSArray *theList;
Code:
@property(nonatomic, copy) NSArray *theList;
.m file
Code:
//in viewDidLoad
theList = [(AppDelegate*)[[UIApplication sharedApplication] delegate]theList];
mutableList = [[NSMutableArray alloc]init];
for(Object *o in theList){
[mutableList addObject:o];
}
Some things I do not understand here:
If i release theList after the code above, the app is crashing. As I defined it with the property copy I thought I have to release it when I do not want to use it anymore? theList is a pointer to an NSArray object - ie an object that will not change as long as the app lives. I defined it as copy, as I wrote above, because after analyzing the memory use, this seemed to be the most effective solution. I might be wrong...?
Anyway, after copying the objects from theList into an local mutable array, I thought it would be correct to kill theList...? Why is this wrong? The problem I noticed was when navigating between the different tableViews. The app crashed when I revisited a table, and that problem does not appear with the solution above. The question is only - is this the right way to go? Is it effective? Is it robust? The more I read about memory management on iphone development, the lmore confused I feel.
Thanks in advance for any ideas or comments!
MACloop