Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Recent
    • Tags
    • Users
    • Register
    • Login

    Memory Leak

    Scheduled Pinned Locked Moved SDK Help
    5 Posts 0 Posters 435 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      Helper
      last edited by

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

      On 20/12/2004 at 03:11, xxxxxxxx wrote:

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

      ---------
      Hello
      Now I've got a problem in memory leaking! I tried to make an object using ***Command Plugin. It's working ,but in the debug window it shows memory leaking. So I tried to release the memory after using the BaseObject and String and Vectors ( which are allocated using Alloc or bNew).
      But when I try to do that, Cinema4D crash at all and close down. Here is my code:
      void dlgMyClass::MyObj1()
      {
        BaseDocument *doc = GetActiveDocument();
        BaseObject *obj = doc->GetActiveObject();
        if(obj==NULL)
        {
         MessageDialog("No Selected Object!");
         return;
        }
        PointObject *pObj=ToPoint(obj);
        LONG cnt = pObj->GetPointCount();
        Vector *vObj=pObj->GetPoint();
        BaseSelect *bs = pObj->GetPointS();
        String *arrLocation1 =bNew String[cnt];
        String *XLoc1=bNew String[cnt];
        String *ZLoc1=bNew String[cnt];
        String *arrNames1 = bNew String[j+1];//new(array, j+1);
        BaseObject *ObjObj1 = BaseObject::Alloc(Ocube);
       
        /****************************Here I use them***********************************************/
        doc->Message(MSG_UPDATE);
        EventAdd(EVENT_FORCEREDRAW);
       
        MessageDialog("Releasing the memory!");
        //Releasing the memory
        BaseObject::Free(ObjObj1);
        bDelete(arrLocation1);
        bDelete(XLoc1);
        bDelete(ZLoc1);
        bDelete(arrNames1);
      }
      After the dialog box showing "Releasing the memory!" the program crash. Why? Did I choose the wrong plugin type? I look at the samples of Cinema4D and in their command plugins, I didn't find the creation of the objects.
      Please, do a favour for me ... urgently.
      I'm waiting ...
      With respects,
      ZawMinTun

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

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

        On 20/12/2004 at 07:06, xxxxxxxx wrote:

        If you InsertXX() anything into a C4D Document, it is then OWNED by C4D. Freeing afterwards will crash C4D since your plugin no longer has ownership. If you want to free the memory, you must first Remove() it from the Document.

        Memory management is all about ownership - who or what class owns the allocated memory and is thus responsible for its release.

        Robert

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

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

          On 21/12/2004 at 21:02, xxxxxxxx wrote:

          Hello ...
          Thank you so much, Robert. I'm gonna try it. And I also want to know the reason << why an object is not accessible after SendModelingCommand>>. Let's say ...
          //Sample code
          //mcd is ModelingCommandData
          //Obj1 is Ocube BaseObject
           
              Obj1->SetName(vTempName);
              doc1->InsertObject(Obj1,NULL,NULL);
              doc1->AddUndo(UNDO_NEW, Obj1);
              mcd.doc=doc1;
              mcd.op=Obj1;
              mcd.bc=Obj1->GetDataInstance();
              mcd.mode=MODIFY_ALL;
              mcd.flags=MODELINGCOMMANDFLAG_CREATEUNDO;
              SendModelingCommand(MCOMMAND_MAKEEDITABLE,mcd);
             
              if(Obj1!=NULL)
              {
               MessageDialog("NotNull");
              }
              else
              {
               MessageDialog("Null");
              }
          The MessageDialog("NotNull") shows that Obj1 is not NULL. But when I try to use it , let's say , Obj1->SetPos(Vector(1.0,1.0,1.9));,
          Cinema4D crash. So I must write Obj1=doc->SearchObject(vTempName); .
          This code segment is in a loop. So when I try to make it loop (x) times, the C4DTrace shows that (x-1) block is leaked and each block is
          40 bytes. Firstly I think it because of BaseContainer. So I leave out the BaseContainer variable completely and use it directly using
          GetDataInstance() and not assigning to anything. But the leak is going on. bDelete is OK for now. I think the problem is totally based on
          BaseObject.
          So I try using GetClone ( like the way in the sample program LiquidTool).
          I declare ...........
          BaseObject *Obj1=NULL;
          BaseObject *Obj2=BaseObject::Alloc(Ocube);
          outside the loop.
          In the loop ....
          Obj1=Obj2->GetClone(0,NULL);
          is inserted. Then the above code segment I showed follows.
          Outside the loop I release the Obj2 . No crash. But still leaking.
          Maybe, my letter is complex , if you don't get me, do a favour for me and read it again,please.
          Really thank you so much.
          ZawMinTun

          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

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

            On 21/12/2004 at 22:54, xxxxxxxx wrote:

            Well, Cinema 4D replaces the original object with the 'editable' one. SendModelingCommand(), in these cases, returns a pointer to the new object in mdc.results1. Obj1 doesn't 'exist' any more. Check my code to see what's happening:

              
                 ModelingCommandData cd;  
                 cd.doc = doc;  
                 cd.op = rootObj;  
                 cd.mode = MDATA_CURRENTSTATETOOBJECT_INHERITANCE|MDATA_CURRENTSTATETOOBJECT_KEEPANIMATION;  
                 if (!SendModelingCommand(MCOMMAND_CURRENTSTATETOOBJECT, cd)) throw ErrorException(ERROR_MODELINGCOMMAND, "Current State to Object");  
              
            // *** This is the new, replacement object  
                 rootObj = cd.result1;  
            // ***  
              
                 doc->InsertObject(rootObj, NULL, NULL, FALSE);  
            

            Robert

            1 Reply Last reply Reply Quote 0
            • H Offline
              Helper
              last edited by

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

              On 27/12/2004 at 00:22, xxxxxxxx wrote:

              Hello ...
              Thank you so much ... and very good is your explanation.
              I get it. Sorry for my late reply. Internet connection is not so good in our company.
              See again and happy new year.
              ZawMinTun

              1 Reply Last reply Reply Quote 0
              • First post
                Last post