• 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: NSData being retained?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSData being retained?


  • Subject: Re: NSData being retained?
  • From: James DiPalma <email@hidden>
  • Date: Thu, 22 Jul 2004 13:09:23 -0700

Why is [aUrl release] in your code? Did not two people explain that releasing an autoreleased object is a bad idea? [data release] caused a bus error, [aUrl release] should cause an exception.

These two lines of code should not be leaking memory (they both should return autoreleased objects that will get released during [localPool release]:

NSURL* aUrl = [NSURL URLWithString:urlString];
NSData *data = [aUrl resourceDataUsingCache:NO];

You may test my statement by commenting these lines of code out and seeing if you still see memory getting allocated but never released. If these lines are leaking, it is a bug. Unfortunately, if they are leaking, it is not likely to be their returned object that is leaking, but something else; I don't have any suggestions for fixing this kind of leak.

There remains a few other possibilities:
- "looping" in your while statement (which is outside of localPool)
- "a_string_i_got_from_somewhere"
- your perception of a memory leak

Since you are making some fairly basic errors in trying to fix your memory leak (releasing already autoreleased objects, setting variables to nil), it is difficult to guess what you know about memory management. I suggest showing all of your code so that we can get a more complete picture of all code that is being executed during your leaky loop and maybe an explanation of how you detected a leak.

With what code you have shown, I don't know enough to help you find a leak.


-jim


On Jul 22, 2004, at 11:50 AM, Jim Ways wrote:

Here is a breakdown of what i am doing

NSAutoreleasePool *mainPool = [[NSAutoreleasePool
alloc] init];

while(looping)
{
NSAutoreleasePool *localPool = [[NSAutoreleasePool
alloc] init];

NSString *urlString = a_string_i_got_from_somewhere
NSURL* aUrl = [NSURL URLWithString:urlString];
NSData *data = [aUrl resourceDataUsingCache:NO];
[aUrl release]; //with or without this line i get it

[localPool release];
}

[mainPool release];

--- Shawn Erickson <email@hidden> wrote:

On Jul 22, 2004, at 11:13 AM, Jim Ways wrote:

NSURL* aUrl = [NSURL URLWithString:urlString];
NSData *data = [aUrl resourceDataUsingCache:NO];
[aUrl release];

This allocates memory but never releases it, if i
[data release]; i get a bus error.

If i set data to
nil i still get an increase in memory each loop.

The
contents of data dont seem to increase with each cycle
but i cant track down where the memory is comming
from.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >Re: NSData being retained? (From: Jim Ways <email@hidden>)

  • Prev by Date: Re: Redirecting screencapture output
  • Next by Date: Re: IOBluetooth questions
  • Previous by thread: Re: NSData being retained?
  • Next by thread: where does one do the autorelease?
  • Index(es):
    • Date
    • Thread