Memory Leak with WMI

D

Don Nell

Hello

Why is there a memory leak when this VB code is executed.


do
set locator = createobject("wbemscripting.swbemlocator")
set oWMI = locator.connectserver("MachineName" ,
"root/cimv2","UserName","Password")
loop


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
 
N

NewsReader

Change your loop to look more like this and see what happens:

do
set locator = createobject("wbemscripting.swbemlocator")
set oWMI = locator.connectserver("MachineName" ,
"root/cimv2","UserName","Password")

set oWMI = Nothing
set locator = Nothing
loop
 
D

Don Nell

Hi,

I tried your suggestions but there was no difference.

I also tried doing the same thing in C++, C#, and Delphi (see code below)
but like my VB sample, they all showed a 4Kb memory leak per connection.

I also found that by leaving the username and password blank, the leak still
existed, but it was slower.

Thanks anyway.

Don

//****************************­******************************­*
C++ Example */
//****************************­******************************
while(1==1)
{
CoInitializeEx(0, COINIT_APARTMENTTHREADED) ;
CoInitializeSecurity
(
NULL, -1, NULL, NULL,
RPC_C_AUTHN_LEVEL_DEFAULT,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL, EOAC_NONE, 0
) ;


ISWbemLocator *t_Locator = NULL ;
HRESULT t_Result = CoCreateInstance (


CLSID_SWbemLocator ,
NULL ,
CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER ,
IID_ISWbemLocator,
( void ** ) & t_Locator
) ;


ISWbemServices *t_Service = NULL ;


t_Result = t_Locator->ConnectServer (


L"computername" ,
L"root\\cimv2",
L"username" ,
L"password" ,
NULL ,
0 ,
NULL,
NULL,
&t_Service
) ;


t_Service->Release () ;
t_Locator->Release () ;
CoUninitialize();


}


//****************************­******************************­*
//Delphi Example - Call Make Connection 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('Mac­hineName', 'root\cimv2',
'UserName', 'Password', '', '', 0, pService);


end;


end.
 
S

swindal

Hi Don,
I know it has been a while since you posted that message.
I am now running into the same issue in C++. Did you find a workaround
by any chance?

Thanks,
Sebastien
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top