Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

Getting a memory leak when closing a Tabbed doc.

I have a form with a few dummy controls and 4 Stringlists which I create and free in the forms Create and Destroy events.
A new instance of the form is created when a new tabbed dock is created.  The form has a DocClose event which simply sets Action to caFree.

I can see in debug that my destroy code is being executed on closing the tab but when I close the application I get a memory leak for each form created.  
See attached memory leak report for a single tabbed doc.

If I don't set Action but just close the application there is no memory leak.

How should I close the form without causing this memory leak.


txt
txt
MemoryManager_EventLog.txt
4K
Tagged:

Comments

  • 3 Comments sorted by Votes Date Added
  • I thought it might be helpful to show my Dock Create code in case I am doing something wrong here

    function TfmIDEMain.CreateDock(PageType:tIDEPageType): TLMDDockPanel;
    var editor: TFmEditor;

      procedure DockAsTabbedDoc(APanel: TLMDDockPanel);
      var zn: TLMDDockZone;
        begin
          zn := dsMain.SpaceZone;
          while (zn <> nil) and (zn.Kind <> zkTabs) and (zn.ZoneCount > 0) do
            zn := zn[0];
          if zn <> nil then
            DsMain.DockControl(APanel, zn, alClient, zn.ZoneCount -1)
        end;

    begin
      Result := TLMDDockPanel.Create(Self); // Create new Panel
      Result.ClientKind := dkDocument;
      Result.Tag := Integer(PageType);      // Add in page type
      try
        case PageType of
          ptEditor: begin   // Create an editor page
            editor := TfmEditor.Create(Result);
            Result.OnClose      := editor.DocClose;
            Result.OnEnter      := editor.DocEnter;
            Editor.Parent       := Result;
          end;
        end;
        DockAsTabbedDoc(Result);
      except
        Result.Free;
        raise;
      end;
    end;

    function TfmIDEMain.AddPage(FileName: string; PageType: TIDEPageType): TLMDDockPanel;
    Var s : String;
    begin
      if (PageType > ptNone) and (PageType <= ptWeb) then begin
        ActivePanel := CreateDock(PageType);   // creates an instance of Page Type
        with ActivePanel do begin
          Caption := ChangeFileExt(ExtractFileName(FileName),'');
          ShowHeaderImage := hiShow;
          Images := vilEdTabsLR;
          case PageType of
            ptEditor: begin
              ActiveEditor := TfmEditor(Controls[0]);
              ImageIndex := 1;
            end;
          end;
        if Zone <> nil then
          begin
            Zone.Index := Zone.Parent.ZoneCount - 1;
            Show;
            UpdateTitleBarCaption;
          end;
        end;
      end;
    end;

  • Please create and send to our support email small isolated demo project.
  • Email Sent to Support with Demonstrator.

Sign In or Register to comment.