Jump to content

Reduction to 90% memory usage


Recommended Posts

Good personal day,

for those who like performance with low memory consumption, following a static class that reduces memory consumption in UniGui applications.

I'm already using this class on systems that there are many users connected and memory-intensive.

to call the class:

TGarbageCollector.Execute;

unit U_GarbageCollector;

interface

type
  TGarbageCollector = class
    private
    public
      class procedure Execute;
  end;

implementation

uses
  Winapi.Windows, Vcl.Forms;


{ TGarbageCollector }

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

end;

end.
  • Upvote 3
Link to comment
Share on other sites

I think that it's a bad thing.

You're telling to page all your inactive memory to disk. It obeys. The moment you touch any of that memory again, the OS has to page it back into RAM. You're forcing disk I/O that you don't actually know you need.

and yes you are releasing memory, but you are forcing disk i/o, if your application is losing memory, that's not the way.

  • Upvote 1
Link to comment
Share on other sites

Hello  Marlon,

 

  You are not releasing memory, you are forcing your process to move some of it's memory used to the windows swap file, but your process will still allocate the same memory as before.

 

to be sure of that, in task manager, add column "peak working set" next to "memory" column, after executing TGarbageCollector.Execute, the peak memory will remain that same, which is what your process memory, the memory tab only show the current memory using in Ram of your process, but not what your process allocated in memory.

 

docjones, also is right, you are forcing more I/O which will lead to slower performance, but not optimizing the memory.

 

Regards,

Mohammed

  • Upvote 1
Link to comment
Share on other sites

  • 9 months later...
  • 3 years later...

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...