FROM : Chris Suter
DATE : Tue Feb 26 23:15:47 2008
On 27/02/2008, at 4:59 AM, Quincey Morris wrote:
>
> On Feb 26, 2008, at 02:42, Chris Suter wrote:
>
>> The observation info uses a weak reference and it will have been
>> zeroed before finalize is called so neither of the above are a
>> problem. Even so, I'm not sure it's a good idea to call
>> removeObserver: from the finalize method.
>
> A weak reference to what? If you mean to the observed object, that
> brings us full circle. My original question was whether the
> references to observed objects are weak, and the answer I got was no.
The reference to the observer is a weak reference. The reference to
the observed object isn't and that's where the leak comes from.
>> Knowing this, you might wonder if you have to call removeObserver
>> at all in the GC case. I just ran some tests and it looks like you
>> do otherwise you'll get a memory leak which is a shame because it
>> would be easy to clean up automatically.
>
> Do you know what's leaking? Are we talking about an observation info
> object that's sitting there with a zeroed reference to the observee?
> If so, I agree it's a shame, but I'm not sure how easy it would be
> for the observation code to detect without a lot of scanning.
Yes, it's the observation info that gets leaked. All observation info
appears to get stored in a global dictionary:
NSKeyValueObservationInfoPerObject and it's an entry in that that gets
leaked. It should be easy to make it automatically clear up; use a
NSMapTable rather than a dictionary.
- Chris
DATE : Tue Feb 26 23:15:47 2008
On 27/02/2008, at 4:59 AM, Quincey Morris wrote:
>
> On Feb 26, 2008, at 02:42, Chris Suter wrote:
>
>> The observation info uses a weak reference and it will have been
>> zeroed before finalize is called so neither of the above are a
>> problem. Even so, I'm not sure it's a good idea to call
>> removeObserver: from the finalize method.
>
> A weak reference to what? If you mean to the observed object, that
> brings us full circle. My original question was whether the
> references to observed objects are weak, and the answer I got was no.
The reference to the observer is a weak reference. The reference to
the observed object isn't and that's where the leak comes from.
>> Knowing this, you might wonder if you have to call removeObserver
>> at all in the GC case. I just ran some tests and it looks like you
>> do otherwise you'll get a memory leak which is a shame because it
>> would be easy to clean up automatically.
>
> Do you know what's leaking? Are we talking about an observation info
> object that's sitting there with a zeroed reference to the observee?
> If so, I agree it's a shame, but I'm not sure how easy it would be
> for the observation code to detect without a lot of scanning.
Yes, it's the observation info that gets leaked. All observation info
appears to get stored in a global dictionary:
NSKeyValueObservationInfoPerObject and it's an entry in that that gets
leaked. It should be easy to make it automatically clear up; use a
NSMapTable rather than a dictionary.
- Chris
| Related mails | Author | Date |
|---|---|---|
| Quincey Morris | Feb 25, 03:30 | |
| Rob Keniger | Feb 25, 06:45 | |
| glenn andreas | Feb 25, 16:02 | |
| David Carlisle | Feb 26, 05:00 | |
| Rob Keniger | Feb 26, 05:38 | |
| Bill Bumgarner | Feb 26, 06:08 | |
| Quincey Morris | Feb 26, 09:01 | |
| Chris Suter | Feb 26, 11:42 | |
| Sean McBride | Feb 26, 16:51 | |
| Quincey Morris | Feb 26, 18:59 | |
| Chris Suter | Feb 26, 23:15 | |
| Graham | Feb 26, 23:36 | |
| Quincey Morris | Feb 27, 00:37 | |
| Mark Piccirelli | Feb 27, 02:07 | |
| Antonio Nunes | Feb 27, 07:59 | |
| Chris Suter | Feb 27, 08:08 |






Cocoa mail archive

