|
Antwort |
Registriert seit: 11. Okt 2003 Ort: Elbflorenz 44.063 Beiträge Delphi 12 Athens |
#11
Nja, bei deim einem Speicherleck, in meinem Code, lag es daran, daß die Schnittstelle nur als Out-Parameter definiert ist, weswegen der entsprechende "alte" Inhalt des Variants nie freigegeben wurde, da der Variant selber einfach nur überschrieben wurde.
Leider wird dieses Problem in vielen Codes nicht beachtet, wodurch diese vielen Lecks überall entstehen. Tja, und darum erstmal der der Versuch von oben (VarClear), wobei das mit dem ADsFreeEnumerator(varArr) sogar im MSDN drinstand und es dennoch in seinem Code fehlte. Jetzt hat er erstmal was zum Probieren und ich bin gespannt, ob sich was ändert.
Neuste Erkenntnis:
Seit Pos einen dritten Parameter hat, wird PoSex im Delphi viel seltener praktiziert. |
Zitat |
Registriert seit: 12. Mär 2007 486 Beiträge |
#12
Servus,
VarClear(varArr) hat weitergeholfen. Habe zwei VarClear(varArr) in den while schleifen eingebaut und nun past es. Wenn die Funktion aufgerufen wird steigt der Speicher nur einmalig um +2MB, denke wegen der activeds.dll einbindung. thx |
Zitat |
Registriert seit: 14. Aug 2004 1.439 Beiträge Delphi 2007 Professional |
#13
Hier auch noch mal dir Frage
Hat wer ein funktionierendes Beispiel das eine einfache WMI Abfrage macht, die kein Memory Leak hat?
Gruss Hans
2B or not 2B, that is FF |
Zitat |
Gruber_Hans_12345 |
Öffentliches Profil ansehen |
Mehr Beiträge von Gruber_Hans_12345 finden |
t.roller
(Gast)
n/a Beiträge |
#14
Delphi-Quellcode:
// This code was generated by the Wmi Delphi Code Creator http://theroadtodelphi.wordpress.com
// Version: 1.8.3.0 // LIABILITY DISCLAIMER // THIS GENERATED CODE IS DISTRIBUTED "AS IS". NO WARRANTY OF ANY KIND IS EXPRESSED OR IMPLIED. // YOU USE IT AT YOUR OWN RISK. THE AUTHOR NOT WILL BE LIABLE FOR DATA LOSS, // DAMAGES AND LOSS OF PROFITS OR ANY OTHER KIND OF LOSS WHILE USING OR MISUSING THIS CODE. program GetWMI_Info; {$APPTYPE CONSOLE} uses (* SysUtils, ActiveX, ComObj, Variants; *) Winapi.Windows, System.SysUtils, Winapi.ActiveX, System.Win.ComObj, System.Variants; function VarToInt(const AVariant: Variant): INT64; begin Result := StrToIntDef(Trim(VarToStr(AVariant)), 0); end; // "CIM_MemoryCapacity" beschreibt den Speichertyp, der auf einem physikalischen // Element installiert werden kann, und seine minimale/maximale Konfiguration. // Instanzen der Klasse "CIM_PhysicalMemory" enthalten Informationen über die // Speicherposition und die minimalen/maximalen Anforderungen. procedure GetCIM_MemoryCapacityInfo; const WbemUser =''; WbemPassword =''; WbemComputer ='localhost'; wbemFlagForwardOnly = $00000020; var FSWbemLocator : OLEVariant; FWMIService : OLEVariant; FWbemObjectSet: OLEVariant; FWbemObject : OLEVariant; oEnum : IEnumvariant; iValue : LongWord; begin; FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator'); FWMIService := FSWbemLocator.ConnectServer(WbemComputer, 'root\CIMV2', WbemUser, WbemPassword); FWbemObjectSet:= FWMIService.ExecQuery('SELECT * FROM CIM_MemoryCapacity','WQL',wbemFlagForwardOnly); oEnum := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant; while oEnum.Next(1, FWbemObject, iValue) = 0 do begin Writeln(Format('Caption %s',[VarToStr(FWbemObject.Caption)]));// String Writeln(Format('Description %s',[VarToStr(FWbemObject.Description)]));// String Writeln(Format('MaximumMemoryCapacity %d',[VarToInt(FWbemObject.MaximumMemoryCapacity)]));// Uint64 Writeln(Format('MemoryType %d',[VarToInt(FWbemObject.MemoryType)]));// Uint16 Writeln(Format('MinimumMemoryCapacity %d',[VarToInt(FWbemObject.MinimumMemoryCapacity)]));// Uint64 Writeln(Format('Name %s',[VarToStr(FWbemObject.Name)]));// String Writeln(''); FWbemObject:=Unassigned; end; end; procedure GetCIM_PhysicalMemoryInfo; const WbemUser =''; WbemPassword =''; WbemComputer ='localhost'; wbemFlagForwardOnly = $00000020; var FSWbemLocator : OLEVariant; FWMIService : OLEVariant; FWbemObjectSet: OLEVariant; FWbemObject : OLEVariant; oEnum : IEnumvariant; iValue : LongWord; begin; FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator'); FWMIService := FSWbemLocator.ConnectServer(WbemComputer, 'root\CIMV2', WbemUser, WbemPassword); FWbemObjectSet:= FWMIService.ExecQuery('SELECT * FROM CIM_PhysicalMemory','WQL',wbemFlagForwardOnly); oEnum := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant; while oEnum.Next(1, FWbemObject, iValue) = 0 do begin Writeln(Format('BankLabel %s',[VarToStr(FWbemObject.BankLabel)]));// String Writeln(Format('Capacity %d',[VarToInt(FWbemObject.Capacity)]));// Uint64 Writeln(Format('Caption %s',[VarToStr(FWbemObject.Caption)]));// String Writeln(Format('CreationClassName %s',[VarToStr(FWbemObject.CreationClassName)]));// String Writeln(Format('DataWidth %d',[VarToInt(FWbemObject.DataWidth)]));// Uint16 Writeln(Format('Description %s',[VarToStr(FWbemObject.Description)]));// String Writeln(Format('FormFactor %d',[VarToInt(FWbemObject.FormFactor)]));// Uint16 Writeln(Format('HotSwappable %s',[VarToStr(FWbemObject.HotSwappable)]));// Boolean Writeln(Format('InstallDate %s',[VarToStr(FWbemObject.InstallDate)]));// Datetime Writeln(Format('InterleavePosition %d',[VarToInt(FWbemObject.InterleavePosition)]));// Uint32 Writeln(Format('Manufacturer %s',[VarToStr(FWbemObject.Manufacturer)]));// String Writeln(Format('MemoryType %d',[VarToInt(FWbemObject.MemoryType)]));// Uint16 Writeln(Format('Model %s',[VarToStr(FWbemObject.Model)]));// String Writeln(Format('Name %s',[VarToStr(FWbemObject.Name)]));// String Writeln(Format('OtherIdentifyingInfo %s',[VarToStr(FWbemObject.OtherIdentifyingInfo)]));// String Writeln(Format('PartNumber %s',[VarToStr(FWbemObject.PartNumber)]));// String Writeln(Format('PositionInRow %d',[VarToInt(FWbemObject.PositionInRow)]));// Uint32 Writeln(Format('PoweredOn %s',[VarToStr(FWbemObject.PoweredOn)]));// Boolean Writeln(Format('Removable %s',[VarToStr(FWbemObject.Removable)]));// Boolean Writeln(Format('Replaceable %s',[VarToStr(FWbemObject.Replaceable)]));// Boolean Writeln(Format('SerialNumber %s',[VarToStr(FWbemObject.SerialNumber)]));// String Writeln(Format('SKU %s',[VarToStr(FWbemObject.SKU)]));// String Writeln(Format('Speed %d',[VarToInt(FWbemObject.Speed)]));// Uint32 Writeln(Format('Status %s',[VarToStr(FWbemObject.Status)]));// String Writeln(Format('Tag %s',[VarToStr(FWbemObject.Tag)]));// String Writeln(Format('TotalWidth %d',[VarToInt(FWbemObject.TotalWidth)]));// Uint16 Writeln(Format('Version %s',[VarToStr(FWbemObject.Version)]));// String Writeln(''); FWbemObject:=Unassigned; end; end; procedure GetWin32_PerfRawData_PerfOS_MemoryInfo; const WbemUser =''; WbemPassword =''; WbemComputer ='localhost'; wbemFlagForwardOnly = $00000020; var FSWbemLocator : OLEVariant; FWMIService : OLEVariant; FWbemObjectSet: OLEVariant; FWbemObject : OLEVariant; oEnum : IEnumvariant; iValue : LongWord; begin; FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator'); FWMIService := FSWbemLocator.ConnectServer(WbemComputer, 'root\CIMV2', WbemUser, WbemPassword); FWbemObjectSet:= FWMIService.ExecQuery('SELECT * FROM Win32_PerfRawData_PerfOS_Memory','WQL',wbemFlagForwardOnly); oEnum := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant; while oEnum.Next(1, FWbemObject, iValue) = 0 do begin Writeln(Format('AvailableBytes %d',[VarToInt(FWbemObject.AvailableBytes)]));// Uint64 Writeln(Format('AvailableKBytes %d',[VarToInt(FWbemObject.AvailableKBytes)]));// Uint64 Writeln(Format('AvailableMBytes %d',[VarToInt(FWbemObject.AvailableMBytes)]));// Uint64 Writeln(Format('CacheBytes %d',[VarToInt(FWbemObject.CacheBytes)]));// Uint64 Writeln(Format('CacheBytesPeak %d',[VarToInt(FWbemObject.CacheBytesPeak)]));// Uint64 Writeln(Format('CacheFaultsPersec %d',[VarToInt(FWbemObject.CacheFaultsPersec)]));// Uint32 Writeln(Format('Caption %s',[VarToStr(FWbemObject.Caption)]));// String Writeln(Format('CommitLimit %d',[VarToInt(FWbemObject.CommitLimit)]));// Uint64 Writeln(Format('CommittedBytes %d',[VarToInt(FWbemObject.CommittedBytes)]));// Uint64 Writeln(Format('DemandZeroFaultsPersec %d',[VarToInt(FWbemObject.DemandZeroFaultsPersec)]));// Uint32 Writeln(Format('Description %s',[VarToStr(FWbemObject.Description)]));// String Writeln(Format('FreeAndZeroPageListBytes %d',[VarToInt(FWbemObject.FreeAndZeroPageListBytes)]));// Uint64 Writeln(Format('FreeSystemPageTableEntries %d',[VarToInt(FWbemObject.FreeSystemPageTableEntries)]));// Uint32 Writeln(Format('Frequency_Object %d',[VarToInt(FWbemObject.Frequency_Object)]));// Uint64 Writeln(Format('Frequency_PerfTime %d',[VarToInt(FWbemObject.Frequency_PerfTime)]));// Uint64 Writeln(Format('Frequency_Sys100NS %d',[VarToInt(FWbemObject.Frequency_Sys100NS)]));// Uint64 Writeln(Format('LongTermAverageStandbyCacheLifetimes %d',[VarToInt(FWbemObject.LongTermAverageStandbyCacheLifetimes)]));// Uint32 Writeln(Format('ModifiedPageListBytes %d',[VarToInt(FWbemObject.ModifiedPageListBytes)]));// Uint64 Writeln(Format('Name %s',[VarToStr(FWbemObject.Name)]));// String Writeln(Format('PageFaultsPersec %d',[VarToInt(FWbemObject.PageFaultsPersec)]));// Uint32 Writeln(Format('PageReadsPersec %d',[VarToInt(FWbemObject.PageReadsPersec)]));// Uint32 Writeln(Format('PagesInputPersec %d',[VarToInt(FWbemObject.PagesInputPersec)]));// Uint32 Writeln(Format('PagesOutputPersec %d',[VarToInt(FWbemObject.PagesOutputPersec)]));// Uint32 Writeln(Format('PagesPersec %d',[VarToInt(FWbemObject.PagesPersec)]));// Uint32 Writeln(Format('PageWritesPersec %d',[VarToInt(FWbemObject.PageWritesPersec)]));// Uint32 Writeln(Format('PercentCommittedBytesInUse %d',[VarToInt(FWbemObject.PercentCommittedBytesInUse)]));// Uint32 Writeln(Format('PercentCommittedBytesInUse_Base %d',[VarToInt(FWbemObject.PercentCommittedBytesInUse_Base)]));// Uint32 Writeln(Format('PoolNonpagedAllocs %d',[VarToInt(FWbemObject.PoolNonpagedAllocs)]));// Uint32 Writeln(Format('PoolNonpagedBytes %d',[VarToInt(FWbemObject.PoolNonpagedBytes)]));// Uint64 Writeln(Format('PoolPagedAllocs %d',[VarToInt(FWbemObject.PoolPagedAllocs)]));// Uint32 Writeln(Format('PoolPagedBytes %d',[VarToInt(FWbemObject.PoolPagedBytes)]));// Uint64 Writeln(Format('PoolPagedResidentBytes %d',[VarToInt(FWbemObject.PoolPagedResidentBytes)]));// Uint64 Writeln(Format('StandbyCacheCoreBytes %d',[VarToInt(FWbemObject.StandbyCacheCoreBytes)]));// Uint64 Writeln(Format('StandbyCacheNormalPriorityBytes %d',[VarToInt(FWbemObject.StandbyCacheNormalPriorityBytes)]));// Uint64 Writeln(Format('StandbyCacheReserveBytes %d',[VarToInt(FWbemObject.StandbyCacheReserveBytes)]));// Uint64 Writeln(Format('SystemCacheResidentBytes %d',[VarToInt(FWbemObject.SystemCacheResidentBytes)]));// Uint64 Writeln(Format('SystemCodeResidentBytes %d',[VarToInt(FWbemObject.SystemCodeResidentBytes)]));// Uint64 Writeln(Format('SystemCodeTotalBytes %d',[VarToInt(FWbemObject.SystemCodeTotalBytes)]));// Uint64 Writeln(Format('SystemDriverResidentBytes %d',[VarToInt(FWbemObject.SystemDriverResidentBytes)]));// Uint64 Writeln(Format('SystemDriverTotalBytes %d',[VarToInt(FWbemObject.SystemDriverTotalBytes)]));// Uint64 Writeln(Format('Timestamp_Object %d',[VarToInt(FWbemObject.Timestamp_Object)]));// Uint64 Writeln(Format('Timestamp_PerfTime %d',[VarToInt(FWbemObject.Timestamp_PerfTime)]));// Uint64 Writeln(Format('Timestamp_Sys100NS %d',[VarToInt(FWbemObject.Timestamp_Sys100NS)]));// Uint64 Writeln(Format('TransitionFaultsPersec %d',[VarToInt(FWbemObject.TransitionFaultsPersec)]));// Uint32 Writeln(Format('TransitionPagesRePurposedPersec %d',[VarToInt(FWbemObject.TransitionPagesRePurposedPersec)]));// Uint32 Writeln(Format('WriteCopiesPersec %d',[VarToInt(FWbemObject.WriteCopiesPersec)]));// Uint32 Writeln(''); FWbemObject:=Unassigned; end; end; //------------------------------------------------------------------------------ var memory: TMemoryStatusEx; begin ReportMemoryLeaksOnShutdown := True; memory.dwLength := SizeOf(memory); GlobalMemoryStatusEx(memory); WriteLn('Total memory: ' + IntToStr(memory.ullTotalPhys) + ' Bytes'); WriteLn('Available memory: ' + IntToStr(memory.ullAvailPhys) + ' Bytes'); try CoInitialize(nil); try GetCIM_MemoryCapacityInfo; WriteLn('---------------------------------------------------------------'); GetCIM_PhysicalMemoryInfo; WriteLn('---------------------------------------------------------------'); GetWin32_PerfRawData_PerfOS_MemoryInfo; finally CoUninitialize; end; except on E:EOleException do Writeln(Format('EOleException %s %x', [E.Message,E.ErrorCode])); on E:Exception do Writeln(E.Classname, ':', E.Message); end; Writeln('Press Enter to exit'); Readln; end. |
Zitat |
Ansicht |
Linear-Darstellung |
Zur Hybrid-Darstellung wechseln |
Zur Baum-Darstellung wechseln |
ForumregelnEs 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
|
|
Nützliche Links |
Heutige Beiträge |
Sitemap |
Suchen |
Code-Library |
Wer ist online |
Alle Foren als gelesen markieren |
Gehe zu... |
LinkBack |
LinkBack URL |
About LinkBacks |