Saturday, 29 June 2002
Er, so much for the DockCam release. Still remaining on the to-do list:
- Every other time you open Preferences, the focus changes
- Fix return in combo box not triggering default button
- Check that we aren't leaking NSURLHandles (or anything else for that matter)
The first issue is a bug in my pref handling code which I haven't tracked down; the second is a bug in NSComboBox which I can probably work around, and the third is what I've spent the past two hours trying to figure out.
According to the indispensible OmniObjectMeter, I'm leaking primarily NSConcreteMutableData and NSHTTPURLHandle objects. Watching my process's memory usage, it grabs about 500K per image load. But if I stop the timer which triggers image loading, lots of memory is freed, and the leaks have dropped to about 10K per load. There's an autorelease pool that is waiting for me to stop, but my program isn't designed to do that.
The NSConcreteMutableData objects are being retained by the NSHTTPURLHandle objects, ironically inside a method called 'flushCachedData'. Some flushing it's doing!
The retain-release cycle of a NSHTTPURLHandle object looks like this:
- alloc in my code, from -[NSURL URLHandleUsingCache:]
- autorelease called inside -[NSURL URLHandleUsingCache:] (makes sense…)
- 2 retains in -[NSURLHandle loadInBackground], called by my code
- release in my code, because I explicitly pop the autorelease pool used by -[NSURL URLHandleUsingCache:]
- release in the stream read callback, -[NSHTTPURLHandle performStreamRead:]
- autorelease in the stream read callback
- release in -[NSApplication run]
The problem is that the final release is never triggered until the application is quiescent: when I stop the timer that causes the image to reload. For the moment, I'm stumped. My only thought is to switch from NSURLHandle to Dan Wood's CURLHandle in the hope that it will let me control its allocation behavior.