• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Dodgy Code - Low Level Memory Management Question!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Dodgy Code - Low Level Memory Management Question!
      • From: Jens Alfke <email@hidden>
    • Re: Dodgy Code - Low Level Memory Management Question!
      • From: Quincey Morris <email@hidden>
References: 
 >Dodgy Code - Low Level Memory Management Question! (From: Dave <email@hidden>)
 >Re: Dodgy Code - Low Level Memory Management Question! (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: Removing Observers eats up memory
  • Next by Date: Re: Obj-C - your thoughts on hiding data members?
  • Previous by thread: Re: Dodgy Code - Low Level Memory Management Question!
  • Next by thread: Re: Dodgy Code - Low Level Memory Management Question!
  • Index(es):
    • Date
    • Thread