• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Solving memory leaks
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Solving memory leaks
      • From: Quincey Morris <email@hidden>
References: 
 >Solving memory leaks (From: Michael Davey <email@hidden>)
 >Re: Solving memory leaks (From: Michael Davey <email@hidden>)

  • Prev by Date: Re: Solving memory leaks
  • Next by Date: Re: Solving memory leaks
  • Previous by thread: Re: Solving memory leaks
  • Next by thread: Re: Solving memory leaks
  • Index(es):
    • Date
    • Thread