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 14:18:32 +0100
The problem, OK look at this pseudo code:
MyDict* dict;
-(void)Example {
MyClass* obj = [MyClass new];
char* key = "key";
MyDictStore( dict, key, obj );
}
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.
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.
I dont see the problem... What has casting in C to do with
ObjectiveC's memory management?
RefCount is RefCount and that is all that counts
Of course you need to retain/release and have an autorelase pool.
Regards,
Dominik
_______________________________________________
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.