• 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: Philip Mobley <email@hidden>
  • Date: Sun, 28 Mar 2010 11:03:21 -0700

On Mar 28, 2010, at 10:42 AM, mmalc Crawford wrote:

>> That would be gut for the fact that my fields are released and set to nil whenever a new SELECT query is executed - however, I think I can do this by emptying the array when a new query is done and just counting the size of the array in my fetch method - thanks...
>>
> Why not follow what someone else suggested earlier in the thread, and the pattern that is recommended in the documentation, and use accessor methods. As soon as you start sprinkling retains and releases throughout your code, you're liable to make a mistake.
> <http://developer.apple.com/mac/library/documentation/cocoa/Conceptual/MemoryMgmt/Articles/mmPractical.html#//apple_ref/doc/uid/TP40004447>

Plus when you use accessor, you can put in a call to your NSLog( ) and see exactly whats going on...

- (void)setFields:(NSMutableArray *)newFields {
	NSLog( @"-setFields, old fields value: %p with new value %p", fields, newFields );
	[fields autorelease];
	fields = [newFields mutableCopy];
}

When calling setFields, you are then responsible for releasing the "newFields" NSMutableArray you created in your sample code, because [newFields mutableCopy] increments the ref counter.

_______________________________________________

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: Michael Davey <email@hidden>
    • Re: Solving memory leaks
      • From: mmalc Crawford <email@hidden>
References: 
 >Solving memory leaks (From: Michael Davey <email@hidden>)
 >Solving memory leaks (From: Michael Davey <email@hidden>)
 >Re: Solving memory leaks (From: mmalc Crawford <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