• 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: "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.


  • Follow-Ups:
    • Re: Memory management, when mixing C and ObjC
      • From: Hamish Allan <email@hidden>
    • Re: Memory management, when mixing C and ObjC
      • From: Dominik Pich <email@hidden>
References: 
 >Memory management, when mixing C and ObjC (From: "Theodore H. Smith" <email@hidden>)
 >Re: Memory management, when mixing C and ObjC (From: Dominik Pich <email@hidden>)

  • Prev by Date: Re: Memory management, when mixing C and ObjC
  • Next by Date: Crazy floats
  • Previous by thread: Re: Memory management, when mixing C and ObjC
  • Next by thread: Re: Memory management, when mixing C and ObjC
  • Index(es):
    • Date
    • Thread