-
1)procedure WndProc_LVSubitemDraw comment have some special char, can't compile in chinese windows 2)destructor TMenu.Destroy memory leak, use FastMM4:
if FParentMenu <> nil then begin Prnt := FParentMenu; Next := Prnt.RemoveSubMenu( FId ); FParentMenu := nil; Prnt.FMenuItems.Remove( @ Self ); if Next = nil then Exit; end;
need changed to:
if FParentMenu <> nil then begin Prnt := FParentMenu; FParentMenu := nil; Next := Prnt.RemoveSubMenu( FId ); Prnt.FMenuItems.Remove( @ Self ); if Next = nil then Exit; end;
-
a more good change:
if FParentMenu <> nil then begin Prnt := FParentMenu; Next := Prnt.RemoveSubMenu( FId ); //FParentMenu := nil; Prnt.FMenuItems.Remove( @ Self ); if Next = nil then Exit; {>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>} end;
function TMenu.RemoveSubMenu( ItemToRemove: Integer ): PMenu; {$IFDEF DEBUG_MENU}var OK: Boolean; {$ENDIF} var M: PMenu; begin Result := Items[ ItemToRemove ]; if Result = nil then Exit; {>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>} M := Result.FParentMenu; if M = nil then M := @Self; {$IFDEF DEBUG_MENU} OK := {$ENDIF} RemoveMenu( M.FHandle, Result.FId, MF_BYCOMMAND ); M.FMenuItems.Remove( Result ); {$IFDEF DEBUG_MENU} if not OK then ShowMessage( 'Error removing menu: ' + Int2Str( GetLastError ) + ' - ' + SysErrorMessage( GetLastError ) ); {$ENDIF} if Count = 0 then begin Result.FParentMenu := nil; Result.Free; Result := nil; end; RedrawFormMenuBar; end;
-
final solution:
function TMenu.RemoveSubMenu( ItemToRemove: Integer ): PMenu; {$IFDEF DEBUG_MENU}var OK: Boolean; {$ENDIF} var M: PMenu; begin Result := Items[ ItemToRemove ]; if Result = nil then Exit; {>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>} M := Result.FParentMenu; if M = nil then M := @Self; {$IFDEF DEBUG_MENU} OK := {$ENDIF} RemoveMenu( M.FHandle, Result.FId, MF_BYCOMMAND ); M.FMenuItems.Remove( Result ); {$IFDEF DEBUG_MENU} if not OK then ShowMessage( 'Error removing menu: ' + Int2Str( GetLastError ) + ' - ' + SysErrorMessage( GetLastError ) ); {$ENDIF} //if Count = 0 then begin Result.FParentMenu := nil; Result.Free; Result := nil; end; RedrawFormMenuBar; end;
-
KOL 3.20 new function and procedure is not UNICODE, i think this break 3.18's Unicode style
-
This method solves the problem of memory leaks on destruction menu?
-
modify two method can solves menu meory leak 1)destructor TMenu.Destroy //FParentMenu := nil; 2)function TMenu.RemoveSubMenu( ItemToRemove: Integer ): PMenu; //if Count = 0 then begin Result.FParentMenu := nil; Result.Free; Result := nil; end;
-
So, it's great. Thx!
|