AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Win32/Win64 API (native code) Delphi Eigener Dienst -> Speicherauslastung wächst und wächst...
Thema durchsuchen
Ansicht
Themen-Optionen

Eigener Dienst -> Speicherauslastung wächst und wächst...

Ein Thema von cherry · begonnen am 14. Apr 2008 · letzter Beitrag vom 7. Mai 2008
Antwort Antwort
Seite 5 von 5   « Erste     345   
Benutzerbild von Remko
Remko

Registriert seit: 10. Okt 2006
Ort: 's-Hertogenbosch, Die Niederlande
222 Beiträge
 
RAD-Studio 2010 Arc
 
#41

Re: Eigener Dienst -> Speicherauslastung wächst und wächs

  Alt 2. Mai 2008, 10:40
Some more info on the memory leak. I ran this testprogram:
Delphi-Quellcode:
program WTSLeak;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  JwaWindows;

  type
  { array of TWtsSessionInfoA }
  PWTSSessionInfoAArray = ^TWTSSessionInfoAArray;
  TWTSSessionInfoAArray = array[0..ANYSIZE_ARRAY-1] of TWtsSessionInfoA;

  { array of TWtsSessionInfoW }
  PWTSSessionInfoWArray = ^TWTSSessionInfoWArray;
  TWTSSessionInfoWArray = array[0..ANYSIZE_ARRAY-1] of TWtsSessionInfoW;

var
  SessionInfoPtr: PWTSSessionInfoWArray;
  pCount: DWORD;
  i,j: Integer;
  bRes: Boolean;
  ppBuffer: PWideChar;
  pBytesReturned: DWORD;
begin
  for j := 0 to 10000 do
  begin
    bRes := WTSEnumerateSessionsW(WTS_CURRENT_SERVER, 0, 1,
      PWtsSessionInfoW(SessionInfoPtr), pCount);

    if bRes then
    begin

      for i := 0 to PCount - 1 do
      begin
        bRes := WTSQuerySessionInformationW(WTS_CURRENT_SERVER,
          SessionInfoPtr^[i].SessionId, WTSApplicationName, Pointer(ppBuffer),
          pBytesReturned);

        if bRes then
        begin
          WriteLn(Format('ApplicationName=%s', [ppBuffer]));
          WTSFreeMemory(Pointer(ppBuffer));
        end
        else begin
          WriteLn(Format('WTSQuerySessionInformation for Session %d failed with error %s',
            [SessionInfoPtr^[i].SessionId, SysErrorMessage(GetLastError)]));
        end;
      end;

      WTSFreeMemory(SessionInfoPtr);
    end
    else begin
      WriteLn(Format('WTSEnumerateSessions failed with error %s',
        [SysErrorMessage(GetLastError)]));
    end;
  end;

  ReadLn;

end.
If I look in the VMSize/Private Working Set column of task manager (do not use the Memory Usage/Working Set column) we can cleary see that we leak memory on every call to WTSQuerySessionInformation. I also ran it through a profiler which clearly showed that the memory is being allocated in wtsapi32.dll. Further testing shows that the memory is only leaked when the call to WTSQuerySessionInformation fails (it does this on special sessions like the console and the listener sessions). If the call does fail wtsapi leaks exactly 2664 bytes on each call, which is the size of WinStationQueryInformation structure 1 (this is an undocumented api called by wtsapi32.dll internally).
  Mit Zitat antworten Zitat
Benutzerbild von cherry
cherry

Registriert seit: 14. Nov 2005
561 Beiträge
 
RAD-Studio 2009 Ent
 
#42

Re: Eigener Dienst -> Speicherauslastung wächst und wächs

  Alt 7. Mai 2008, 15:50
Zitat von Remko:
PS: see my post above, maybe you can revert to the original code?
das habe ich nun auch gemacht, es schint prima zu funktionieren und für meinen Dienst die passendste Lösung zu sein.

Vielen Dank euch allen!
Ist das nur mein Gefühl, oder ist die ganze Welt verrückt geworden!?
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 5 von 5   « Erste     345   


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 04:17 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz