On 28/06/2013 at 11:23, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 13
Platform: Windows ;
Language(s) : C++ ;
---------
Hi,
I'm getting memory leaks when I run my custom UD sorting method.
The method is used to look for UD entries that are out of order. Then it copies their values, deletes it, and re-creates them with a lower level ID#. So my UD entries are always sequential in order.
FYI: The reason I need them to stay in sequential order because I'm using the UD entries to drive a Gedialog layout. And it's crucial that they stay in sequential order with no jumps or gaps in their ID#s.
The method is working fine. And doing what it's supposed to do. But I'm getting a memory leak from it. And I can't figure out why.
I think the leaks are coming from this line of code: BaseContainer data = *bc->GetClone(COPYFLAGS_0, NULL);
The method code:
void udSequential()
{
for(LONG i=0; i<100; i++)
{
BaseDocument *doc = GetActiveDocument();
BaseObject *obj = doc->GetActiveObject();
if(!obj) return;
BaseTag *tag = obj->GetTag(TAG_PLUGIN_ID); //My tag's plugin ID is: TAG_PLUGIN_ID
if(!tag) return;
DynamicDescription *ud = tag->GetDynamicDescription();//The master UD container
GeAutoDynamicArray<LONG>order; //Will be used to store the UD item's levels and compare them
DescID dscID = NULL; //Each UD item is a DescID type object
const BaseContainer *bc;
void *dscHnd = ud->BrowseInit(); //Initialize the Browse function
while(ud->BrowseGetNext(dscHnd, &dscID, &bc)) //Loop through the UserData entries
{
LONG level = dscID[1].id; //Get the leve ID# for each UD item
order.Push(level); //Add this level number to the array
LONG arrSize = order.GetCount(); //Get the length of the array
LONG last = order[arrSize-1]; //Get the last array element
LONG previous = order[arrSize-2]; //Get the second to last array element
LONG diff = last - previous; //Get the amount of the difference
if(diff > 1) //If the levels are not sequential
{
BaseContainer data = *bc->GetClone(COPYFLAGS_0, NULL); //Copy the UD item's container
GeData d; //Create a GeData container to hold the UD item's gizmo values
tag->GetParameter(dscID, d, DESCFLAGS_GET_0); //Copy the UD item's data to the "d" variable
String name = bc->GetString(DESC_NAME); //Copy the UD item's label
LONG type = bc->GetLong(DESC_CUSTOMGUI); //Copy the UD item's Type
LONG unit = bc->GetLong(DESC_UNIT); //Get the units setting(Real, Percent. etc..)
ud->Remove(dscID); //Delete the UD item (Note: This doesn't remove the level info)
dscID.PopId(); //Delete the UD item's level from the UD stack
dscID.PushId(level - 1); //Add the UD back to the UD stack with a lower level ID#
ud->Set(dscID, data, NULL);
tag->SetParameter(DescID(dscID), GeData(d), DESCFLAGS_SET_0);//Paste the copied data to this new version with new level#
}
}
ud->BrowseFree(dscHnd); //Free the memory used by the BrowseGetNext() function
}
}
Every time the method executes I get a leak with these two names:
btree_container(some random number)
ge_container.cp(some random number)
Any ideas why C4D is refusing to let go of the memory for this?
-ScottA