• 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: Leak in NSData +dataWithContentsOfURL:
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Leak in NSData +dataWithContentsOfURL:


  • Subject: Re: Leak in NSData +dataWithContentsOfURL:
  • From: "Timothy J. Wood" <email@hidden>
  • Date: Fri, 15 Mar 2002 11:55:16 -0800

On Thursday, March 14, 2002, at 05:42 PM, Jonathan Feinberg wrote:
I finally managed to chase down the memory leak in my app. I believe that the NSData class method dataWithContentsOfURL:(NSURL *)url leaks memory. I have hacked up a quick demo, which you'll find at


Actually, this doesn't appear to be the problem as far as I can tell. Using OmniObjectMeter 2.0 (which is soon to go into beta! :), it looks like the problem is that -[NSHTTPURLHandle dealloc] is busted.

(Please feel free to copy the information below into your existing bug report with Apple).

The data you see being leaked is allocated here:

0x70008e20 in _malloc_zone_calloc
0x706b33d4 in __internal_class_createInstanceFromZone
0x708134c0 in _NSAllocateObject
0x70847498 in +[NSMutableData allocWithZone:]
0x7082ea88 in +[NSObject alloc]
0x7087d1c8 in -[NSHTTPURLHandle loadInForeground]
0x708afd28 in -[NSURLHandle resourceData]
0x708aec28 in -[NSURL resourceDataUsingCache:]
0x7082dfd4 in -[NSData initWithContentsOfURL:]
0x708511a4 in +[NSData dataWithContentsOfURL:]
0x00003ba4 in -[DemoController fetchURL:] (DemoController.m:35  /Volumes/DemonstrateNSDataLeak)
0x70833b28 in -[NSObject performSelector:withObject:]
0x70c94698 in -[NSApplication sendAction:to:from:]
0x70c8bbb4 in -[NSControl sendAction:to:]
0x70c94778 in -[NSCell _sendActionFrom:]
0x70cdf34c in -[NSCell trackMouse:inRect:ofView:untilMouseUp:]
0x70cd2210 in -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:]
0x70cfaef0 in -[NSControl mouseDown:]
0x70c1b8f8 in -[NSWindow sendEvent:]
0x70b9479c in -[NSApplication sendEvent:]
0x005f0344 in __dyld_func_lookup
0x70c23488 in -[NSApplication run]
0x70c91ed0 in _NSApplicationMain
0x00003978 in _main (main.m:13  /Volumes/DemonstrateNSDataLeak)
0x0000389c in __start
0x000036cc in start

The owning NSHTTPURLHandle experiences the following three events. First it is allocated, then autoreleased and finally the NSAutoreleasePool releases it. OmniObjectMeter is claiming that the NSHTTPURLHandle isn't getting deallocated though. This is a symptom of not calling [super dealloc] in your -dealloc implementation.

So, based on this I would say that -[NSHTTPURLHandle dealloc] has two bugs:

- It isn't releasing an NSData ivar.
- It isn't calling [super dealloc].

0x70008e20 in _malloc_zone_calloc
0x706b33d4 in __internal_class_createInstanceFromZone
0x708134c0 in _NSAllocateObject
0x7082732c in +[NSObject allocWithZone:]
0x708ad1bc in -[NSURL URLHandleUsingCache:]
0x708aec1c in -[NSURL resourceDataUsingCache:]
0x7082dfd4 in -[NSData initWithContentsOfURL:]
0x708511a4 in +[NSData dataWithContentsOfURL:]
0x00003ba4 in -[DemoController fetchURL:] (DemoController.m:35  /Volumes/DemonstrateNSDataLeak)
0x70833b28 in -[NSObject performSelector:withObject:]
0x70c94698 in -[NSApplication sendAction:to:from:]
0x70c8bbb4 in -[NSControl sendAction:to:]
0x70c94778 in -[NSCell _sendActionFrom:]
0x70cdf34c in -[NSCell trackMouse:inRect:ofView:untilMouseUp:]
0x70cd2210 in -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:]
0x70cfaef0 in -[NSControl mouseDown:]
0x70c1b8f8 in -[NSWindow sendEvent:]
0x70b9479c in -[NSApplication sendEvent:]
0x005f0344 in __dyld_func_lookup
0x70c23488 in -[NSApplication run]
0x70c91ed0 in _NSApplicationMain
0x00003978 in _main (main.m:13  /Volumes/DemonstrateNSDataLeak)
0x0000389c in __start
0x000036cc in start

0x708163a8 in _NSAutoreleaseObject
0x7081d02c in -[NSObject autorelease]
0x708ad1dc in -[NSURL URLHandleUsingCache:]
0x708aec1c in -[NSURL resourceDataUsingCache:]
0x7082dfd4 in -[NSData initWithContentsOfURL:]
0x708511a4 in +[NSData dataWithContentsOfURL:]
0x00003ba4 in -[DemoController fetchURL:] (DemoController.m:35  /Volumes/DemonstrateNSDataLeak)
0x70833b28 in -[NSObject performSelector:withObject:]
0x70c94698 in -[NSApplication sendAction:to:from:]
0x70c8bbb4 in -[NSControl sendAction:to:]
0x70c94778 in -[NSCell _sendActionFrom:]
0x70cdf34c in -[NSCell trackMouse:inRect:ofView:untilMouseUp:]
0x70cd2210 in -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:]
0x70cfaef0 in -[NSControl mouseDown:]
0x70c1b8f8 in -[NSWindow sendEvent:]
0x70b9479c in -[NSApplication sendEvent:]
0x005f0344 in __dyld_func_lookup
0x70c23488 in -[NSApplication run]
0x70c91ed0 in _NSApplicationMain
0x00003978 in _main (main.m:13  /Volumes/DemonstrateNSDataLeak)
0x0000389c in __start
0x000036cc in start

0x70812618 in _NSDecrementExtraRefCountWasZero
0x708115ac in -[NSObject release]
0x708121f0 in _NSPopAutoreleasePool
0x70824b04 in -[NSAutoreleasePool release]
0x00003c40 in -[DemoController fetchURL:] (DemoController.m:40  /Volumes/DemonstrateNSDataLeak)
0x70833b28 in -[NSObject performSelector:withObject:]
0x70c94698 in -[NSApplication sendAction:to:from:]
0x70c8bbb4 in -[NSControl sendAction:to:]
0x70c94778 in -[NSCell _sendActionFrom:]
0x70cdf34c in -[NSCell trackMouse:inRect:ofView:untilMouseUp:]
0x70cd2210 in -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:]
0x70cfaef0 in -[NSControl mouseDown:]
0x70c1b8f8 in -[NSWindow sendEvent:]
0x70b9479c in -[NSApplication sendEvent:]
0x005f0344 in __dyld_func_lookup
0x70c23488 in -[NSApplication run]
0x70c91ed0 in _NSApplicationMain
0x00003978 in _main (main.m:13  /Volumes/DemonstrateNSDataLeak)
0x0000389c in __start
0x000036cc in start


-tim
_______________________________________________
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: 
 >Leak in NSData +dataWithContentsOfURL: (From: Jonathan Feinberg <email@hidden>)

  • Prev by Date: NSThread and notifications
  • Next by Date: How do I give an IB object a custom icon?
  • Previous by thread: Leak in NSData +dataWithContentsOfURL:
  • Next by thread: Re: Leak in NSData +dataWithContentsOfURL:
  • Index(es):
    • Date
    • Thread