Re: Re: Memory management, when mixing C and Obj C
Re: Re: Memory management, when mixing C and Obj C
- Subject: Re: Re: Memory management, when mixing C and Obj C
- From: <email@hidden>
- Date: Fri, 23 Jul 2004 15:46:01 +0200
"Theodore H. Smith" <email@hidden> schrieb am 23.07.2004,
15:18:32:
>
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.
>
Is this code better?
>
>
MyDict* dict;
>
-(void)Example {
>
MyClass* obj = [MyClass new];
>
char* key = "key";
>
MyDictStore( dict, key, obj );
>
SomehowIncrementRefCountOfNSObject( obj );
>
}
>
>
Of course, when the dictionary is disposed, it needs to run through all
>
the objects to release them.
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 ;-)
Regards,
Kay
_______________________________________________
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.