• 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: Memory leak in simple code?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Memory leak in simple code?


  • Subject: Re: Memory leak in simple code?
  • From: Shawn Erickson <email@hidden>
  • Date: Thu, 7 Apr 2005 11:16:21 -0700


On Apr 7, 2005, at 10:37 AM, Shawn Erickson wrote:


On Apr 7, 2005, at 9:49 AM, Matt Neuburg wrote:

On Wed, 06 Apr 2005 23:45:07 -0500, Jason von Nieda <email@hidden>
said:
   // The next line is the one causing the leak. If I comment it out
the program does not leak and if I try to
   // release or autorelease "results" the program crashes.
   NSString *results = [NSString stringWithContentsOfURL:nsURL];

So don't do that. Do this:

NSString* results = [[NSString alloc] initWithContentsOfURL:nsURL];
[results release];

In other words, to avoid the messy unknowns of convenience constructors,
avoid convenience constructors.

Nothing is unknown about how they will function from the point of view of who owns responsibility for returned objects, it is clearly stated in the memory contract that the Cocoa framework follows.

It may be better to say "should function" in my sentence above since a possibility exists for a bug in NSString (or something it uses) that makes it not correctly follow the expected memory contract.


I don't know if a bug is involved in this situation or not. If a bug does exist it could easily exist in initWithContentsOfURL as well.

-Shawn

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Re: Memory leak in simple code? (From: Matt Neuburg <email@hidden>)
 >Re: Memory leak in simple code? (From: Shawn Erickson <email@hidden>)

  • Prev by Date: Re: NSWindow class that allocs its own controller?
  • Next by Date: Reordering views
  • Previous by thread: Re: Memory leak in simple code?
  • Next by thread: Re: Memory leak in simple code?
  • Index(es):
    • Date
    • Thread