kattunga / IWBootstrapFramework

Intraweb Bootstrap 3 Framework for Delphi
http://kattunga.github.io/IWBootstrapFramework
MIT License
98 stars 42 forks source link

IWBSButton DataTarget will create an access violation on destroy with FastMM enabled. #31

Open littleearth opened 7 years ago

littleearth commented 7 years ago

FastMM will raise an exception when DataTarget is assigned on a IWBSButton and destruction of the form. This is a work around I have found to ensure it is set to NIL

destructor TIWBSButton.Destroy;
var
  LDataTarget: Pointer;
begin
  try
    if Assigned(FDataTarget) then
    begin
      LDataTarget := @FDataTarget;
      if LDataTarget <> nil then
      begin
        try
          Pointer(FDataTarget) := nil;
        except
        end;
      end;
    end;
  finally
    inherited;
  end;
end;

To replicate enabled FastMM4 debug options on the IWBSDemo start demo and then exit.

To fix without using this above, edit Unit2 and add a FormDestroy event

IWBSButton49.DataTarget := nil;

kattunga commented 7 years ago

Yes, I can reproduce this.

But what is the reason for this happening? Why only happen with FullDebugMode enabled? Why only happen with FDataTarget and not with FDataParent?

And how did you find this fix?

ronaldhoek commented 7 years ago

Might be because de IDE itself is holding a reference to the interface - this way the object will not be freed when de application is closed and FastMM collects the informaiton about non-freed memory.

You can reproduce this even with a simple project without FastMM and 'ReportMemoryLeaksOnShutdown' set to true. Just at the 'DataTarget' to your watchlist....