Re: Dodgy Code - Low Level Memory Management Question!
Re: Dodgy Code - Low Level Memory Management Question!
- Subject: Re: Dodgy Code - Low Level Memory Management Question!
- From: Dave <email@hidden>
- Date: Tue, 26 Jan 2016 14:00:53 +0000
Hi Again
\
> On 25 Jan 2016, at 19:22, Quincey Morris <email@hidden> wrote:
>
> On Jan 25, 2016, at 10:48 , Dave <email@hidden <mailto:email@hidden>> wrote:
>>
>> myNewObject = [super initWithSomething: something];
>
> This is a dangerous thing to do. At this point ‘self’ might not be a properly initialized object, if the ‘super’ call returns a different object from ‘self’. You’re better off assigning the result to ‘self’ as usual.
Ok, great.
>> [LTWCacheManager addToCache: myID];
>
> Huh? You’re not passing the object being cached, so how can you get it out of the cache again later? If the ID is a string that contains the object pointer, then at the very least the object isn’t being retained by the cache, is it?
Sorry typeo in the pseudo code, it passes the object and it is retained….
>> self = myNewObject;
> […]
>> return self;
>
>> self = myCachedObject;
>> return self;
>
> These aren’t really meaningful. Assigning to ‘self’ doesn’t really achieve anything, other than the possibility of getting it wrong. If you want to return an object other than self, then just write ‘return myNewObject’ or ‘return myCachedObject’.
>
Ok, point noted. My question is, after then it is autoreleased, does this cause a problem, what happens after the first time? If its not in use by anything else, then the cached object will have a retainCount of 1, so it will need just one release (when the cache is cleared) which will cause it to dealloc, is this correct? IOW, the autorelease will basically just be a NOP?
Thanks for taking your time on this, just want to make sure I understand MMM correctly in this case as its been a while since I have had to do anything this horrid!
All the Best
Dave
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden