ss2006
ss2006

Reputation: 217

Crash in FinalizeUnits [finalization of Classes.pas]

My application gets struck in an infinite loop in the finalization section in classes.pas (Delphi 2010) when calling ReleaseObjectInstanceBlocks.

ReleaseObjectInstanceBlocks calls GetFreeInstBlockItemCount(InstFreeList, Block) and the problem seems to be in the InstFreeList linked list. The function traverses that list, and it seems the list is pointing to a circular reference (and creates an infinite loop).

Any pointers on how do I find out what is causing an error at this stage? (All my forms have been freed by this time obviously)

Update & More Details

I have located the problem to be a conflict between Owner & Parent. I construct a form (which I use as a "frame" by placing it on a panel) using constructor TfrSMDControl.Create(AOwner:TComponent; AParent:TWincontrol; id:TStepperMotorDrive); which creates a few ActiveX components in runtime.

The crash occurs given two conditions

  1. if the frame is created with different Owner and parent. e.g., frSMD := TfrSMDControl.Create(MainForm, Panel1, idControl);
  2. An exception occurs in the destructor code (in which case Delphi tries to free this object a second time -even though the error is caught using a try except block).

I free the object with a FreeAndNil(frSMD) using the following destructor

try CWDIO.Free; CWPulse.Free; CWDAQTools.Free; except on e:exception do MyDBG.LogException(E.Message); end;

No crash occurs if the frame is created with frSMD := TfrSMDControl.Create(nil, Panel1, idControl); (with the same destructor exception handling code).

CWxxx are all Ole/ActiveX components. Is there an issue with how Delphi handles ownership of and exception in OleControls ?)

Upvotes: 0

Views: 526

Answers (1)

David Heffernan
David Heffernan

Reputation: 612954

The shared global structure supporting MakeObjectInstance has been corrupted. With probability very close to 1 this is because your program breaks the VCL threading model. Somewhere in your program you are calling VCL code in a thread other than the main thread.

Upvotes: 1

Related Questions