THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 09/05/2009 at 12:24, xxxxxxxx wrote:
Cinema 4D Version: r11
Platform: Windows ;
Language(s) : C++ ;
Hi there, i just like to know where, why and in which case i should need Free(); or GeFree(); What exactly happens if i dont use it, for example within an objectplugin? I am using this:
Vector *pnrm = ToPoly(res)->CreatePhongNormals(); and the manual tells to use GeFree();
Is it a question of filling up the memory with unneccessary data??
thanks for clarifying
On 09/05/2009 at 12:34, xxxxxxxx wrote:
Hi, with GeAlloc you allocate a range of memory which is available until you call GeFree. If you dont free allocated memory it is a memory leak becaue you wasted memory until you end the app. (your OS will clear the range). So if the documentation tells you to use GeFree - do it, otherwise you get problems (or your customer).
Look for "malloc and free" which is a C command and is similar to GeAlloc and GeFree (or maybe they are exactly the same, they just redirect the command).
In your case..
> Vector *pnrm = ToPoly(res)->CreatePhongNormals();
> /* do what you want */
Its similar to gNew and gDelete. So just pair these commands and you will get no problems.
edit: See "Debug information" in the C++ SDK Documentation with information how to detect memoryleaks.
On 09/05/2009 at 13:03, xxxxxxxx wrote:
And keep in mind 'ownership'. If you allocate an object and insert into a document:
BaseObject* obj = BaseObject::Alloc(Ocube);
if (obj) doc->InsertObject(obj, NULL, NULL, FALSE);
Then doc now handles freeing the object and you shouldn't attempt to free it yourself. To free it yourself, you must remove it from the document list:
obj = NULL;
On 09/05/2009 at 14:18, xxxxxxxx wrote:
thanks! i guess i'll have to add some of those now