Re: Memory management of C arrays in objects
Re: Memory management of C arrays in objects
- Subject: Re: Memory management of C arrays in objects
- From: ∞ <email@hidden>
- Date: Sun, 16 Dec 2007 21:29:38 +0100
Il giorno 16/dic/07, alle ore 21:05, Jason Horn ha scritto:
If I have a class that contains several large C arrays, do I have to
free them in a dealloc method in the class, or do they get freed
automatically when the object is freed? If not, what's the right
syntax for freeing a C array?
If you allocate memory on the heap with malloc(), thus declaring your
variables as pointers (type* var), the space will not be recycled by
the system on object deallocation, and usually you will free() during
your dealloc or risk leaking memory.
If you allocate memory in the object itself by declaring a fixed-size
array (type var[5]) as an instance variable of the object, then the
array will take up space in the memory structure of the object itself
and will be recycled as part of the object being freed (just as it
happens for structs containing fixed-size arrays in vanilla C).
- ∞
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden