_memrpt Memory Report

Top  Previous  Next

 

[D1,D2,D3,D4,D5,D6,D7,D8, D2005W, D2005N, D2006W, D2006N, D2007W]

 

The Memory Report helps you find possible memory leaks in your code.

 

__________________________________________________

 

Local objects with unprotected calls to Free

This section reports locations where calls to Free (and FreeAsNil) are not done in try-finally blocks. Failure to wrap a try-finally block around a memory deallocation could result in a memory leak. The report does not list locations in FormDestroy and FormClose events, because these are normally called when a form is destroyed. Neither does it report calls to Free from a finalization block. Also an object that is freed in a try-except block is not reported.

 

__________________________________________________

 

Non-local objects with unprotected calls to Free

Like the previous section, but for non-local objects.

 

__________________________________________________

 

Objects created in try-structure

This section lists lists locations where an object is created inside a try-structure, like:

 

try

Obj := TMyObject.Create;

  …

finally

Obj.Free;

end;

 

Here, Obj should be created before the “try”, otherwise Obj.Free will be called even if the object fails to create, possibly causing a runtime error.

 

__________________________________________________

 

Unbalanced Create/Free

This section reports objects that are not created and freed the same number of times.

This can indicate an error, like in the following example:

 

procedure LocalProc;

var

Obj : TMyClass;

begin

  Obj := TmyClass.Create;

  Obj.DoSomething;

end;

 

Here, the locally declared object Obj is never freed, so this code will cause a memory leak.

 

__________________________________________________

 

Local objects that are created more than once without being freed in-between

This section reports objects that are created more than once (in a row) without being freed in-between.

This leads to memory leakage, like in the following example:

 

procedure LocalProc;

var

Obj : TMyClass;

begin

Obj := TMyClass.Create;

 

try

   Obj := TMyClass.Create;

 

   try

     ..

   finally

     FreeAndNil(Obj);

   end;

 

   ..

finally

   FreeAndNil(Obj);

end

end;

 

Here, the locally declared object Obj is only freed once, which causes a memory leak.

 

 

See also:

 

R_GEN General Reports