Jump to content

Recommended Posts

Posted

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
Posted

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
Posted

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
  • Administrators
Posted

When your OS runs out of physical memory it will automatically use virtual memory by writing to swap file. If your app is 32-bit and you hit the upper memory limit your app will crash anyway regardless of physical/virtual memory.

Posted

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

 

Regards,

Mohammed

Yes, no optimizing memory, only temporally released and writed to disk.

regards

  • 9 months later...
  • 3 years later...
Posted
I'm using TMS Aurelius, my server was about to restart IIS every day, I decided to take it, I notice a memory accumulation, but in my tests there is no memory leak, does anyone have any questions to find these problems?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...