• 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: Understanding ARC
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Understanding ARC


  • Subject: Re: Understanding ARC
  • From: Jens Alfke <email@hidden>
  • Date: Sun, 25 May 2014 09:46:58 -0700

On May 25, 2014, at 2:07 AM, Jamie Ojomoh <email@hidden> wrote:

> So if I use alloc/init then autoreleasepool doesn't work?

No, I meant that the string hasn’t been autoreleased at all yet, so the pool isn’t going to release it when it exits. The pool “works”, it’s just not necessary.

> Or don't I need autoreleasepool at all?

You don’t need it. You only need an autorelease pool if
(a) You’re running a lengthy loop that allocates/autoreleases objects on every iteration; wrapping the body in a pool, keeps those objects from building up
(b) You’re implementing a C callback, i.e. from something like a CF or Unix API.

> Is there any difference in memory releasing / ARC between a class and a
> instance method?

No. Those are totally unrelated concepts.

> And why is it that memory automatically gets released properly when an
> application quits,

It’s part of the job of an operating system to clean up resources left behind by processes.

> but when a class is released any memory that hasn't been
> freed or released properly hangs around forever?  Is this not something
> that can be asked here?

Classes don’t get released, objects do. I’m not quite sure what you’re asking. Within a process, individual memory blocks have to be explicitly freed. NSObject does this by keeping track of reference counts and freeing the memory when the ref-count drops to zero. If an object isn’t released enough times, it’ll stay around until the process quits.

Releasing/freeing objects is kind of like cleaning up your room after you’re done using things; you have to remember to put each thing away.
The process quitting is like your house getting bulldozed. Everything that was in it is gone, there’s nothing left until a new house gets built.

Anyway, YOU ARE OVERTHINKING THIS. Stop trying to figure out when things are getting released — that’s ARC’s job. Just write your code.

—Jens
_______________________________________________

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: Understanding ARC
      • From: Jamie Ojomoh <email@hidden>
References: 
 >Understanding ARC (From: Jamie Ojomoh <email@hidden>)
 >Re: Understanding ARC (From: Jamie Ojomoh <email@hidden>)

  • Prev by Date: Re: NSURL from non-url NSString
  • Next by Date: Re: NSURL from non-url NSString
  • Previous by thread: Re: Understanding ARC
  • Next by thread: Re: Understanding ARC
  • Index(es):
    • Date
    • Thread