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: Quincey Morris <email@hidden>
- Date: Mon, 25 Jan 2016 11:22:26 -0800
- Feedback-id: 167118m:167118agrif8a:167118smBO64LLMx:SMTPCORP
On Jan 25, 2016, at 10:48 , Dave <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.
> [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?
> 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’.
_______________________________________________
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