Memory Leak with WMI

From: Don Nell (donnell_at_nospam.com)
Date: 03/16/05


Date: Wed, 16 Mar 2005 03:02:16 GMT

Hello

Why is there a memory leak when the procedure "MakeConnection" is called
repeatedly in a loop.

unit WmiDelphiTest;

interface

uses Wbemads;

procedure MakeConnection ();

implementation

procedure MakeConnection ();
var
 WbemLocator: ISWbemLocator;
 pService: ISWbemServices;
begin

  WbemLocator := CoSWbemLocator.create;
 pService := WbemLocator.ConnectServer('MachineName', 'root\cimv2',
'UserName', 'Password', '', '', 0, pService);

end;

end.

There is no leak if the username and password is blank and the computer is
in a domain. At first I thought it had something to do with Windows'
inablility to release more than 9 security context entries per 10 seconds
(see link below), but the leak still exist when I slow it down.

http://support.microsoft.com/default.aspx?scid=kb;en-us;890196

I also tried calling RpcMgmtEnableIdleCleanup() at startup and also forcing
any unused memory back to the operating system with
SetProcessWorkingSetSize(...) but nothing helps. The Windows task manger
always shows my application consuming more and more memory until it finally
crashes.

Thanks.

Don



Relevant Pages

  • Memory Leak with WMI
    ... Why is there a memory leak when this code is executed. ... There is no leak if the username and password is blank and the computer is ... The Windows task manger always shows my application ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: MDAC memory leak
    ... Most libraries place the decision of when to free ... There's a capability of breaking on a particular memory allocation, ... leak 500 objects, on the second test I leak 3, because I fixed the bug). ... "App shows memory leak on some machines." ...
    (microsoft.public.vc.mfc)
  • Re: MDAC memory leak
    ... Also when we used some of the memory leak tools suggested on microsoft site ... A mutex is a considerably less efficient synchronization ... "App shows memory leak on some machines." ...
    (microsoft.public.vc.mfc)
  • Re: Memory leak in the Driver
    ... Paul G. Tobey wrote: ... driver development, it's most likely that you are at fault. ... The QFE has no impact on the leak but one thing is sure, ... i am sure that all the memory that i am allocating in my driver is ...
    (microsoft.public.windowsce.platbuilder)
  • Re: Memory leak in the Driver
    ... Don't forget that "handles" are memory, too, as are USB packets, data ... someone else is supposed to free it or, maybe, someone else is allocating it ... and *you* are supposed to free it, could be the source of the leak. ... driver development, it's most likely that you are at fault. ...
    (microsoft.public.windowsce.platbuilder)