Init call



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 18/02/2006 at 15:53, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   9.5 
    Platform:   Windows  ;   
    Language(s) :     C++  ;

    ---------
    I've found out that Init() in my NodeData plugin is called at any change in Atribute manager, which, if i understand this correctly, creates for every of the public pointers in Object : public ObjectData class new variable, but the old ones still exist, creating a steadily growing memory usage... I tried to use free(*void) in CopyTo rutine (since this one is called together with Init, but no luck at all. Can anybody help, PLEASE.

    Thanks in advance,
    Regards



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 18/02/2006 at 16:13, xxxxxxxx wrote:

    That is because the object is being cloned for display or render on updates. Not the same instance. The clones are owned by Cinema 4D so there is really no reason to do anything about it. You can do something like this to assure that multiple allocs aren't happening on the same pointer though:

      
    class MyObjData : ObjectData  
    {  
          MyPointer* myPtr;  
          ...  
    }  
      
    MyObjData::MyObjData()  
    {  
          myPtr = NULL;  
    }  
    Bool MyObjData::Init()  
    {  
          if (!myPtr)  
          {  
                // Alloc here, e.g.:  
                if (!(myPtr = (MyPointer* )gNew MyPointer)))  
          }  
    }
    

    Definitely donot free() the memory in CopyTo() unless you want to cause a crash situation. CopyTo() should only be worried about allocating and copying class data from source to dest node that is not stored in BaseContainers (such as arrays).



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 18/02/2006 at 16:21, xxxxxxxx wrote:

    hmm... tried it, but still no luck. Does actually myPtr=NULL do anything about the previously created variable, or does that one still exist after that? Or maybe the problem is in pointers in object which aren't declared as pointers in "main class"...

    thanks all the same,
    regards



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 18/02/2006 at 16:32, xxxxxxxx wrote:

    myPtr=NULL just guarantees a valid NULL value whenever the class is instantiated (in the constructor).

    One thing to be sure of is to deallocate the memory - not in CopyTo()!! ;) Deallocate it in Free(), ala GeFree(myPtr); No need to check if it equals NULL first as GeFree() will do nothing if that is the case.

    Otherwise, you have a memory leak and it is not related to multiple calls of Init().



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 18/02/2006 at 16:47, xxxxxxxx wrote:

    aha, GeFree then... hmm... the problem is, Free() is not called in this case (change in AM)...



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 18/02/2006 at 17:53, xxxxxxxx wrote:

    When all else fails, deallocate in the class destructor:

    MyObjData::~MyObjData()  
    {  
          GeFree(myPtr);  
    }  
    void MyObjData::Free()  
    {  
          GeFree(myPtr);  
          myPtr = NULL;  
    }  
    

    It is always called on the deletion of the class. Again, it doesn't matter if you call it here and in MyObjData::Free() since it will only deallocate once, but it is best to nullify it in Free() nonetheless.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 22/02/2006 at 14:50, xxxxxxxx wrote:

    destructor isn't call either... that's weird. really weird. Init's called every time, and destructor and free aren't until i delete the object...



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 23/02/2006 at 04:21, xxxxxxxx wrote:

    nevermind, solved. Init is called every time a new clone is created, while execute is not, thus all array allocations should be in execute instead in init.


Log in to reply