0

I use the following command to reduce the memory usage of my program, I'm actually testing it, only when I compile the program in 64bit this command does not work fot, no error occurs, only the memory in task managerIt does not decrease too, since in compiling 32bit works perfectly, does anyone know the detail is lacking to operate also in 64bit?

procedure TrimAppMemorySize;
var
  MainHandle : THandle;
begin
 try
  MainHandle := OpenProcess(PROCESS_ALL_ACCESS, false, GetCurrentProcessID) ;
  SetProcessWorkingSetSize(MainHandle, $FFFFFFFF, $FFFFFFFF) ;
  CloseHandle(MainHandle) ;
 except
 end;
  Application.ProcessMessages;
end;

thanks!

Dark Ducke
  • 145
  • 1
  • 3
  • 12
  • 2
    Burn this code along with [`that article`](http://delphi.about.com/od/windowsshellapi/ss/setprocessworkingsetsize-delphi-program-memory-optimize_5.htm). – TLama Jun 15 '15 at 15:00
  • The code in your question will result in worse performance. You can solve your problems by deleting all of this code. – David Heffernan Jun 15 '15 at 15:08
  • Here is something worth to read http://stackoverflow.com/q/6059707/960757. – TLama Jun 15 '15 at 15:09
  • One of the sweet things about this function is the call to `Application.ProcessMessages`. One cannot imagine why the author put it there. Perhaps the author just sprays around calls to `Application.ProcessMessages` for the heck of it. Its presence should have been a tell tale sign. The text in that article is astoundingly bad. I shuddered to read it. – David Heffernan Jun 15 '15 at 16:08

1 Answers1

3

The documentation tells you to pass high(SIZE_T). You do this when compiling for 32 bit, but not for 64 bit. This is what you mean to write:

SetProcessWorkingSetSize(MainHandle, high(SIZE_T), high(SIZE_T));

Do note though that this code won't help performance on your machine. In fact, the only thing it can do is make the performance worse. Please remove this code.

SetProcessWorkingSetSize - Whats the catch?

Community
  • 1
  • 1
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • I have an application that makes creating a idhttp in runtime and makes a few posts, and over time the memory in use is increasing too, already checked all the code, and everything that is created is destroyed at the end with FreeAndNil and the time application gets slow to catch, do not know what is causing this excessive use of memory, so I'm behind such a solution... – Dark Ducke Jun 15 '15 at 16:38
  • 1
    `SetProcessWorkingSetSize` doesn't do what you think it does. It will make the performance worse not better. – David Heffernan Jun 15 '15 at 16:39