1 Reply Latest reply on Jun 9, 2014 5:15 AM by A. Patterson

    In the plug-in to draw paths with the mouse move, memory usage increases.

    Pulluran

      In the plug-in to draw paths with the mouse move, a problem that continues to increase memory usage has occurred.

      Is this a specification?Is there a way to free up memory?

      The following code is a modified version of the MultiArrowPlugin.cpp (MultiArrow Samplecode in the SDK).

       

      /*

      *ToolMouseDrag -> TrackToolCursor

      */

      ASErr MultiArrowToolPlugin::ToolMouseDrag(AIToolMessage* message)

      {

          AIErr error = kNoErr;

          ai::int32 cursorId = kHeadArrowToolIconResID;

        

          if ( message->tool == this->fToolHandle[1] )

              cursorId = kTailArrowToolIconResID;

          else if ( message->tool == this->fToolHandle[2] )

              cursorId = kBothEndsArrowToolIconResID;

          else if ( message->tool == this->fToolHandle[3] )

              cursorId = kStraightLineToolIconResID;

       

          if(sAIUser != NULL)

              error = sAIUser->SetCursor(cursorId, fResourceManagerHandle);

       

          return error;

      }

         ・・・An omission)・・・

      /*

      *ToolMouseDrag -> TrackToolCursor

      */

      ASErr MultiArrowToolPlugin::TrackToolCursor(AIToolMessage* message)

      {

          ASErr error = kNoErr;

          AIArtHandle path;

          AIPathSegment segments[8];

          AIReal pathAngle, arrowAngle;

          AIRealPoint arrowPt1, arrowPt2;

          AIPathStyle pathStyle;

          AIPathStyleMap pathStyleMap;

          AIDictionaryRef advStrokeParams = NULL;

        

          error = sAIUndo->UndoChanges( );

       

          this->fEndPoint = message->cursor;

       

          // Invalidate the old Annotation

          error = InvalidateRect(oldAnnotatorRect);

          aisdk::check_ai_error(error);

        

          // Create new art, we will fill it with points below.

          error = sAIArt->NewArt( kPathArt, kPlaceAboveAll, NULL, &path );

          if ( error )

              goto error;

            

         ・・・An omission)・・・

        

       error = sAIPath->SetPathClosed( path, true );

          if ( error )

              goto error;

            

          // fill and stroke with black; 1 point line

          error = sAIPathStyle->GetCurrentPathStyle( &pathStyle, &pathStyleMap, &advStrokeParams );

          pathStyle.fillPaint = true;

          pathStyle.fill.color.kind = kGrayColor;

          pathStyle.fill.color.c.g.gray = kAIRealOne;

        

          pathStyle.strokePaint = true;

          pathStyle.stroke.color.kind = kGrayColor;

          pathStyle.stroke.color.c.g.gray = kAIRealOne;

          pathStyle.stroke.width = kAIRealOne;

          error = sAIPathStyle->SetPathStyle( path, &pathStyle );

       

      error:

          return error;

      }

        • 1. Re: In the plug-in to draw paths with the mouse move, memory usage increases.
          A. Patterson Level 4

          One of two things is happening, both of which are bad. First, UndoChanges() has no effect, in which case you're creating a path every time that event fires, which will be a lot. Second, UndoChanges() is working, in which case you're creating a path every time that event fires, but you're not actually getting rid of it, because Undo doesn't delete the path, it just moves it off the artboard in case you perform a Redo.

           

          So to fix this code, you should do two things.

           

          1. Don't call UndoChanges(). In fact, avoid calling this unless you absolutely have to. It is a very, very, very Bad Idea to call that method unless you really need it and fully understand the implications of doing so; do not use it as short hand for deleting something, because it doesn't actually delete things a lot of the time. Don't feel bad about using it this time though, because I know for a fact that some of Adobe's plugins call when they shouldn't as well
          2. Don't create a path inside the mouse tracking function. If you need functionality like that, make the art handle a variable and only create it if its not already been created. You can append vertices to a path very easily by simply calling AIPathSuite::GetPathSegments(), adding a vertex and then calling AIPathSuite;:SetPathSegments(). Basically, update the path rather than recreate it.