• 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: Memory management, when mixing C and ObjC
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Memory management, when mixing C and ObjC


  • Subject: Re: Memory management, when mixing C and ObjC
  • From: Shawn Erickson <email@hidden>
  • Date: Fri, 23 Jul 2004 09:07:35 -0700

On Jul 23, 2004, at 8:14 AM, Theodore H. Smith wrote:

Now, what happens to obj? Is it disposed? Is it retained? How can the
compiler know when to dispose or retain it? Do I need to add any code
to deal with disposal/refcounts? If MyDictStore is doing all sorts of
crazy stuff with pointers, I don't think that the compiler can figure
that out.

The compiler isn't going to figure anything out. You as a programmer are
responsible to do the memory management, i.e. sending your objects
the proper retain/release/autorelease messages.

But doesn't Cocoa manage to handle objects without any need for explicit memory management, when we are dealing with pure ObjC code? If I do this:

MyClass* obj = [MyClass new];
obj = 0;

doesn't that call MyClass's destructor, and then free the memory? (ala Java).

No. Read over the following very carefully.... (also "new" is generally considered deprecated)

<http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/ index.html>

In particular...

<http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/ Concepts/ObjectOwnership.html>

Objective-C runtime does not provide garbage collection but the Cocoa framework and Mac OS X in general define a memory management contract based on manual reference count (outlined in the referenced documents). If you absolutely want it you can look at mixing in a compatible implementation of the Boehm GC.

-Shawn
_______________________________________________
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: 
 >Re: Re: Memory management, when mixing C and Obj C (From: <email@hidden>)
 >Re: Memory management, when mixing C and ObjC (From: "Theodore H. Smith" <email@hidden>)

  • Prev by Date: Re: Windows and Default Notification Center
  • Next by Date: Re: Java and MacOS
  • Previous by thread: Re: Memory management, when mixing C and ObjC
  • Next by thread: Re: Re: Memory management, when mixing C and Obj C
  • Index(es):
    • Date
    • Thread