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

Re: about dealloc


  • Subject: Re: about dealloc
  • From: Brendan Younger <email@hidden>
  • Date: Sun, 12 May 2002 23:36:33 -0400

On Sunday, May 12, 2002, at 10:24 PM, Antonio Inojal wrote:

Hi, say that I create two private objects in the .h file, meaning, they are global. Now, changing the dealloc method and releasing the objects there, will that release the objects? Let me illustrate my example.

Foo.h
There are, say, two private (non-IB) objects.

can I release those objects from the dealloc method such as:
in Foo.m:

- (void)dealloc
{
[other release];
[myText release];
[super dealloc];
}
where other and myText are two objects. Will this happen? Also, when will the dealloc method get called, at the end of the program?? I appreaciate your time very much. Thank You.

I'm confused by your use of the term "global". If you instantiated them in your -init method (or whatever your designated initializer is), then you *must* release them in your dealloc method. However, if the two objects are global in the sense that every instance of your class Foo has to access them, then releasing them in your dealloc method is not what you want to do.
Also, your dealloc method is called when your instance has a retain count of zero. (That is, no other code has a reference to it.)
I suggest you read the following tutorials to help you understand Cocoa memory management:

Memory Management with Cocoa/WebObjects
http://www.stepwise.com/Articles/Technical/MemoryManagement.html

Hold Me, Use Me, Free Me
http://www.stepwise.com/Articles/Technical/HoldMe.html

Very Simple Rules for Memory Management
http://www.stepwise.com/Articles/Technical/2001-03-11.01.html

Brendan Younger
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >about dealloc (From: Antonio Inojal <email@hidden>)

  • Prev by Date: about dealloc
  • Next by Date: Document with multiple windows
  • Previous by thread: about dealloc
  • Next by thread: Re: about dealloc
  • Index(es):
    • Date
    • Thread