Re: Memory management, when mixing C and ObjC
Re: Memory management, when mixing C and ObjC
- Subject: Re: Memory management, when mixing C and ObjC
- From: "Theodore H. Smith" <email@hidden>
- Date: Fri, 23 Jul 2004 16:14:01 +0100
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).
Looks to me as if SomehowIncrementRefCountOfNSObject( obj ) is a
pseudonym for [obj retain];
You wouldn't expect your compiler to automagically free your malloc'ed
buffers, now would you? This isn't Java ;-)
Well, actually I was expecting "Java-like" behaviour in terms of memory
management, although a closer model would be REALbasic which like ObjC,
also uses proper refcounting.
--
Theodore H. Smith - Software Developer.
http://www.elfdata.com
_______________________________________________
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.