Re: Solving memory leaks
Re: Solving memory leaks
- Subject: Re: Solving memory leaks
- From: Klaus Backert <email@hidden>
- Date: Sat, 27 Mar 2010 22:11:57 +0100
On 27 Mar 2010, at 21:31, Michael Davey wrote:
So, you are saying I should call a retain when I get my reference so
that it is kept as an instance var?
On 27 Mar 2010, at 19:33, Sandor Szatmari wrote:
Every time this method runs you would loose the reference to the
memory previously allocated for the fields array. This happens
when you assign a newly allocated array to feilds.
You should either release fields before reassigning it
(conditionally if it is not nil), or do not reallocate memory for
it, instead empty it and reuse the existing memory.
Assuming fields is an instance variable of some object, you could --
or even should -- access it not directly but via getters and setters,
which do memory management according to the rules, e.g. something like
this (caution: typed in mail, etc.)
@interface MyClass
{
NSMutableDictionary *fields;
}
@property (retain) NSMutableDictionary *myFields;
@end
@implementation MyClass
@synthesize myFields = fields;
...
- (NSDictionary *)fetch
{
...
self.myFields = [[NSMutableArray alloc] init];
...
}
@end
regards
Klaus
_______________________________________________
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