I use MailCore in an iOS app. My app uses NSCoding to cache messages on disk. But I noticed a memory leak via the debugging tools. Each decoded instance leaks.
This can be reproduced with a sample project containing code like:
Note: The test code uses automatic reference counting.
The MCO_SYNTHESIZE_NSCODING macro implements NSCoding.
The initWithCoder initializer always replaces the originally allocated instance of self with the return value of [NSObject mco_objectWithMCObject:] (see the MCO_TO_OBJC macro). In such cases the originally allocated instance should be released. This is explained in detail here:
It was necessary to return a substituted object, in which case release the freshly allocated object first (in memory-managed code)."
I successfully tested the change in my app and my sample, but nothing else. I also didn't write any manual reference count code since 10 years so please review, if this fix makes sense.
I use MailCore in an iOS app. My app uses NSCoding to cache messages on disk. But I noticed a memory leak via the debugging tools. Each decoded instance leaks.
This can be reproduced with a sample project containing code like:
Note: The test code uses automatic reference counting.
The
MCO_SYNTHESIZE_NSCODING
macro implements NSCoding.The
initWithCoder
initializer always replaces the originally allocated instance of self with the return value of[NSObject mco_objectWithMCObject:]
(see theMCO_TO_OBJC
macro). In such cases the originally allocated instance should be released. This is explained in detail here:Apple documentation
I successfully tested the change in my app and my sample, but nothing else. I also didn't write any manual reference count code since 10 years so please review, if this fix makes sense.