MemCheck tutorial: find bad calls

  1. In MemCheck, set DeallocateFreedMemoryWhenBlockBiggerThan to a reasonnable value, eg MaxInt (this value is not reasonnable if your program allocates very big spaces, eg big vectors - then choose for example 1000)
  2. In MemCheck set WipeOutMemoryOnFreeMem to true
  3. Define a class TMyObject
        TMyObject = class
            procedure
    p; virtual;
           
    end;
  4. Define TMyObject with an empty body
  5. Add a procedure BadCall
        procedure BadCall;
           
    var
        t: TMyObject;
            begin
        t:= TMyObject.Create;
        t.Destroy;
        t.p;
            end;
  6. In the dpr's body, just call BadCall
        begin
            MemChk;
            BadCall;
        end.
  7. When you run the program, MemCheck will tell you you are calling P after the object has been destroyed. Better than an access violation, no ? And this is very useful for double destructions.

 




Last update: March 2001