Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/VCL/Standard Controls/TPopupMenu    [ Add a report in this area ]  
Report #:  92878   Status: Closed
Menus.PopupList variable and crash during application quitting
Project:  Delphi Build #:  15.0.3953.35171
Version:    15.1 Submitted By:   Radek Cervinka
Report Type:  Crash / Data loss / Total failure Date Reported:  4/6/2011 3:40:26 AM
Severity:    Infrequently encountered problem Last Updated: 4/7/2011 9:11:52 PM
Platform:    All platforms Internal Tracking #:  
Resolution: Cannot Reproduce (Resolution Comments) Resolved in Build: : None
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: None
Description
finalization section of is menus.pas

finalization
  ShortCutItems.Free;
  PopupList.Free;
  CommandPool.Free;
end.

but sometimes is this section called twice and more (maybe FastMM in debug mode helped) and this leads to AV on PopupList.Free (object is already Free but not nil).

replace with
finalization
  FreeAndNil(ShortCutItems);
  FreeAndNil(PopupList);
  FreeAndNil(CommandPool);
end.
Steps to Reproduce:
I don't know, maybe problem in destructor of TMenuItem or so.

Workarounds
in Main Form of your application write

finalization
  FreeAndNil(PopupList);
end.

// workaround, this free PopupList and set to nil
// so in finalization section of Menus.pas
// and PopupList.Free is OK.
Attachment
None
Comments

Radek Cervinka at 4/6/2011 3:41:58 AM -
See
http://stackoverflow.com/questions/2525236/why-menus-unit-is-finalized-too-early

or QC: 76416

Tomohiro Takahashi at 4/7/2011 2:26:44 AM -
If you have any sample project, could you please attach it to this report in order to reproduce your issue?

Radek Cervinka at 4/7/2011 3:33:07 PM -
I am very sorry, but I can't reproduce this regulary (I have project with 500KLOC and this occured sometimes before workaround). I have some feeling that this is related for using owner drawed own  TMenuItem subclass or exception during finalization of menus.pas, but I am not sure.

But workaround worked good, and suggested replace for FreeAndNil will probably solve this.

Tomohiro Takahashi at 4/7/2011 9:12:56 PM -
Ok, I closed this report as Sysop for the time being. However, if you find any way to rerpoduce your issue, please update this report and put a comment.
Thanks.

Server Response from: ETNACODE01