My understanding is that all memory used by an application (of any sort - variables and dynamic allocation) all happens in the Executables memory space. when the application ends all that memory is then freeded by the operating system .

Write an app that creates a couple of MB of memory dynamically - then kill it in the task manager and watch what happens in the performance window - All the memory comes back.


Here is an example
[pascal]unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons;

type
TForm1 = class(TForm)
BitBtn1: TBitBtn;
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}


type
PListEntry = ^TListEntry;
TListEntry = record
Next: PListEntry;
Text: string;
Count: Integer;
A: Array[1..1000000] of Integer;
end;


var
List, P: PListEntry;

Procedure Load;
Var
I : Integer;
begin
New(P);
P^.Next := List;
P^.Text := 'Hello world';
P^.Count := 1;
For I := 1 to 1000000 do
P^.A[I] := I;
List := P;
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
Load;
end;

end.
[/pascal]

All it requires is a form with a single button. Each time you click the button it allocates over 4MB of memory using NEW. I ran the program up to 400MB of memory and then used task manager to kill it. I Seemed to get it all back.