• 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: Newbie question: how to release an object that has been autoreleased
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie question: how to release an object that has been autoreleased


  • Subject: Re: Newbie question: how to release an object that has been autoreleased
  • From: Scott Stevenson <email@hidden>
  • Date: Tue, 21 Sep 2004 23:58:34 -0700


On Sep 21, 2004, at 8:31 PM, James Bucanek wrote:

I'm fairly new to Cacoa programming and am in the process of creating my first major application. I've got a few basic memory management questions that I can't seemed to find the answers to in the documentation.

Second question: I have an object that has been init'd then autoreleased. How do I destroy it immediately?

Example:

I have a pool of buffers. One message in that buffer pool creates a new buffer object. Like a good Cocoa programmer, I autorelease the object before I return it.

    - (Buffer*)bufferFromPool
    {
        return ( [[[Buffer alloc] initWithMagic] autorelease] );
    }

The client code uses the buffer, but now I want to destroy it immediately after I'm done with it. I can't release it because it's already been autoreleased.

Why do you need it released immediately? The fact that you're running into this at all suggests you're making things more complicated than they need to be.


If it's that important, just ignore the rule and don't return it autoreleased. It would be a good idea to make this clear in the method name (retainedBufferFromPool perhaps). But it would be far better to create a situation where you can let autorelease do its thing normally.


- Scott

--
Tree House Ideas
http://treehouseideas.com/

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Newbie question: how to release an object that has been autoreleased
      • From: mmalcolm crawford <email@hidden>
References: 
 >Newbie question: how to release an object that has been autoreleased (From: James Bucanek <email@hidden>)

  • Prev by Date: Re: Newbie question: autorelease sends autorelease
  • Next by Date: Re: Newbie question: autorelease sends autorelease
  • Previous by thread: Newbie question: how to release an object that has been autoreleased
  • Next by thread: Re: Newbie question: how to release an object that has been autoreleased
  • Index(es):
    • Date
    • Thread