Hello
Why is there a memory leak when this code is executed.
for(;;)
{
ManagementScope scope = new ManagementScope ();
scope.Options.U sername="userna me";
scope.Options.P assword="passwo rd";
scope.Path.Path =@"\\pc\root\ci mv2";
scope.Connect() ;
}
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...b;en-us;890196
I also tried calling RpcMgmtEnableId leCleanup() at startup and also forcing
any unused memory back to the operating system with SetProcessWorki ngSetSize
but nothing helps. The Windows task manger always shows my application
consuming more and more memory until it finally crashes.
Thanks.
Don 4 6092
It is really hard to tell from that small of a code snippet. But you have
an endless loop there, right? Well, in that case you are creating infinite
ManagementScope objects theoretically. Practically, when the garbage
collector is run will be the only time objects are cleaned up. So it would
make sense that if you continually instantiate new objects that your app
would increase in memory size?
Like I said, there is probably more to the picture here, I just don't get it
from the code snippet you provided.
Lastly, as far as when it crashes - what kind of exception do you get when
it does crash?
Take care.
--
Nathan
"Don Nell" <do*****@nospam .com> wrote in message
news:KbNZd.1364 00$tl3.101953@a ttbi_s02... Hello
Why is there a memory leak when this code is executed.
for(;;) { ManagementScope scope = new ManagementScope (); scope.Options.U sername="userna me"; scope.Options.P assword="passwo rd"; scope.Path.Path =@"\\pc\root\ci mv2"; scope.Connect() ;
}
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...b;en-us;890196
I also tried calling RpcMgmtEnableId leCleanup() at startup and also forcing any unused memory back to the operating system with SetProcessWorki ngSetSize but nothing helps. The Windows task manger always shows my application consuming more and more memory until it finally crashes.
Thanks.
Don
Hello Nathan,
Thanks for your response. I first noticed the memory leak in a larger
application I was working on written in C++. I then realized that the leak
can be reproduced in every programming language I tried with a minimal
amount of code. I've included examples in VB, C++, and Delphi below. It all
seems to center around the "Connect" or "ConnectSer ver" call if the username
and password is not blank. The amount of the memory leak is always the same
at around 4Kb per connection.
If the computer running this code is on a domain and can log into the remote
computer using default security (without specifying username and password),
then there is no memory leak even if the username and password is specified.
If not, the memory consumption continues to climb until it either crashes
with an 'access violation' or it simply disappears with the following alert
message.
*************** *************** *************** ******
Windows - Virtual Memory Minimum too low
Your system is low on virtual memory. Windows is
increasing the size of your virtual memory paging
file. During this process, memory requests for
some applications may be denied. For more information,
see help.
*************** *************** *************** ******
Thanks again for your help.
Don
'************** *************** *************** **************
'VB Example
'************** *************** *************** **************
Do
Set locator = CreateObject("w bemscripting.sw bemlocator")
Set oWMI = locator.connect server("wimc096 4", "root/cimv2", "administrator" ,
"system2")
locator = Null
oWMI = Null
Loop
//*************** *************** *************** **************
C++ Example */
//*************** *************** *************** *************
while(1==1)
{
CoInitializeEx( 0, COINIT_APARTMEN TTHREADED) ;
CoInitializeSec urity
(
NULL, -1, NULL, NULL,
RPC_C_AUTHN_LEV EL_DEFAULT,
RPC_C_IMP_LEVEL _IMPERSONATE,
NULL, EOAC_NONE, 0
) ;
ISWbemLocator *t_Locator = NULL ;
HRESULT t_Result = CoCreateInstanc e (
CLSID_SWbemLoca tor ,
NULL ,
CLSCTX_INPROC_S ERVER | CLSCTX_LOCAL_SE RVER ,
IID_ISWbemLocat or,
( void ** ) & t_Locator
) ;
ISWbemServices *t_Service = NULL ;
t_Result = t_Locator->ConnectServe r (
L"computerna me" ,
L"root\\cimv 2",
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.Con nectServer('Mac hineName', 'root\cimv2',
'UserName', 'Password', '', '', 0, pService);
end;
end.
"Nathan Neitzke" <ne******@erau. edu> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. .. It is really hard to tell from that small of a code snippet. But you have an endless loop there, right? Well, in that case you are creating
infinite ManagementScope objects theoretically. Practically, when the garbage collector is run will be the only time objects are cleaned up. So it
would make sense that if you continually instantiate new objects that your app would increase in memory size?
Like I said, there is probably more to the picture here, I just don't get
it from the code snippet you provided.
Lastly, as far as when it crashes - what kind of exception do you get when it does crash?
Take care.
-- Nathan
"Don Nell" <do*****@nospam .com> wrote in message news:KbNZd.1364 00$tl3.101953@a ttbi_s02... Hello
Why is there a memory leak when this code is executed.
for(;;) { ManagementScope scope = new ManagementScope (); scope.Options.U sername="userna me"; scope.Options.P assword="passwo rd"; scope.Path.Path =@"\\pc\root\ci mv2"; scope.Connect() ;
}
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...b;en-us;890196
I also tried calling RpcMgmtEnableId leCleanup() at startup and also forcing any unused memory back to the operating system with SetProcessWorki ngSetSize but nothing helps. The Windows task manger always shows my application consuming more and more memory until it finally crashes.
Thanks.
Don
"Don Nell" <do*****@nospam .com> wrote in message
news:y_TZd.7301 5$r55.15686@att bi_s52... Hello Nathan,
Thanks for your response. I first noticed the memory leak in a larger application I was working on written in C++. I then realized that the leak can be reproduced in every programming language I tried with a minimal amount of code. I've included examples in VB, C++, and Delphi below. It all seems to center around the "Connect" or "ConnectSer ver" call if the username and password is not blank. The amount of the memory leak is always the same at around 4Kb per connection.
If the computer running this code is on a domain and can log into the remote computer using default security (without specifying username and password), then there is no memory leak even if the username and password is specified. If not, the memory consumption continues to climb until it either crashes with an 'access violation' or it simply disappears with the following alert message.
*************** *************** *************** ****** Windows - Virtual Memory Minimum too low Your system is low on virtual memory. Windows is increasing the size of your virtual memory paging file. During this process, memory requests for some applications may be denied. For more information, see help. *************** *************** *************** ******
Thanks again for your help.
Don
'************** *************** *************** ************** 'VB Example '************** *************** *************** ************** Do Set locator = CreateObject("w bemscripting.sw bemlocator") Set oWMI = locator.connect server("wimc096 4", "root/cimv2", "administrator" , "system2") locator = Null oWMI = Null Loop //*************** *************** *************** ************** C++ Example */ //*************** *************** *************** ************* while(1==1) { CoInitializeEx( 0, COINIT_APARTMEN TTHREADED) ; CoInitializeSec urity ( NULL, -1, NULL, NULL, RPC_C_AUTHN_LEV EL_DEFAULT, RPC_C_IMP_LEVEL _IMPERSONATE, NULL, EOAC_NONE, 0 ) ;
ISWbemLocator *t_Locator = NULL ; HRESULT t_Result = CoCreateInstanc e (
CLSID_SWbemLoca tor , NULL , CLSCTX_INPROC_S ERVER | CLSCTX_LOCAL_SE RVER , IID_ISWbemLocat or, ( void ** ) & t_Locator ) ;
ISWbemServices *t_Service = NULL ;
t_Result = t_Locator->ConnectServe r (
L"computerna me" , L"root\\cimv 2", 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.Con nectServer('Mac hineName', 'root\cimv2', 'UserName', 'Password', '', '', 0, pService);
end;
end.
All of your code samples create connections in a closed loop using explicit
cedentials, this results in a RPC context leak as described in http://support.microsoft.com/default...b;en-us;890196.
When using implied credentials the same security context is used for every
new connection (the connection is re-used bo be exact), that's why you don't
see a leak.
Note that this is not a .NET nor a WMI issue, so I would suggest you apply
the patch and try again.
Willy.
I called Microsoft today and installed their hotfix but the problem still
remains. I also see a leak when the username and password are blank but it
is much slower.
Thanks anyway Willy for the suggestion.
Don
"Willy Denoyette [MVP]" <wi************ *@telenet.be> wrote in message
news:eZ******** ******@TK2MSFTN GP15.phx.gbl... "Don Nell" <do*****@nospam .com> wrote in message news:y_TZd.7301 5$r55.15686@att bi_s52... Hello Nathan,
Thanks for your response. I first noticed the memory leak in a larger application I was working on written in C++. I then realized that the
leak can be reproduced in every programming language I tried with a minimal amount of code. I've included examples in VB, C++, and Delphi below. It all seems to center around the "Connect" or "ConnectSer ver" call if the username and password is not blank. The amount of the memory leak is always the same at around 4Kb per connection.
If the computer running this code is on a domain and can log into the remote computer using default security (without specifying username and password), then there is no memory leak even if the username and password is specified. If not, the memory consumption continues to climb until it either
crashes with an 'access violation' or it simply disappears with the following alert message.
*************** *************** *************** ****** Windows - Virtual Memory Minimum too low Your system is low on virtual memory. Windows is increasing the size of your virtual memory paging file. During this process, memory requests for some applications may be denied. For more information, see help. *************** *************** *************** ******
Thanks again for your help.
Don
'************** *************** *************** ************** 'VB Example '************** *************** *************** ************** Do Set locator = CreateObject("w bemscripting.sw bemlocator") Set oWMI = locator.connect server("wimc096 4", "root/cimv2", "administrator" , "system2") locator = Null oWMI = Null Loop //*************** *************** *************** ************** C++ Example */ //*************** *************** *************** ************* while(1==1) { CoInitializeEx( 0, COINIT_APARTMEN TTHREADED) ; CoInitializeSec urity ( NULL, -1, NULL, NULL, RPC_C_AUTHN_LEV EL_DEFAULT, RPC_C_IMP_LEVEL _IMPERSONATE, NULL, EOAC_NONE, 0 ) ;
ISWbemLocator *t_Locator = NULL ; HRESULT t_Result = CoCreateInstanc e (
CLSID_SWbemLoca tor , NULL , CLSCTX_INPROC_S ERVER | CLSCTX_LOCAL_SE RVER , IID_ISWbemLocat or, ( void ** ) & t_Locator ) ;
ISWbemServices *t_Service = NULL ;
t_Result = t_Locator->ConnectServe r (
L"computerna me" , L"root\\cimv 2", 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.Con nectServer('Mac hineName', 'root\cimv2', 'UserName', 'Password', '', '', 0, pService);
end;
end. All of your code samples create connections in a closed loop using
explicit cedentials, this results in a RPC context leak as described in http://support.microsoft.com/default...b;en-us;890196. When using implied credentials the same security context is used for every new connection (the connection is re-used bo be exact), that's why you
don't see a leak.
Note that this is not a .NET nor a WMI issue, so I would suggest you apply the patch and try again.
Willy. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: ranjeet.gupta |
last post by:
Dear All
Is the Root Cause of the Memory corruption is the Memory leak, ??
suppose If in the code there is Memory leak, Do this may lead to the
Memory Corruption while executing the program ?
In nut shell, what is/are the realtion/s between the Memory Leak and
Memory Corruption.
Juts Theoritical Assumtion below:
|
by: José Joye |
last post by:
Hi,
I have implemented a Service that is responsible for getting messages from a
MS MQ located on a remote machine. I'm getting memory leak from time to time
(???). In some situation, it is easier to reproduce (e.g.: remote machine
not available). After about 1 day, I get a usage of 300MB of memory.
I have used .NET Memory Profiler tool to try to see where the leak is
located. For all the leaky instances, I can see the following (I...
|
by: jeevankodali |
last post by:
Hi
I have an .Net application which processes thousands of Xml nodes each
day and for each node I am using around 30-40 Regex matches to see if
they satisfy some conditions are not. These Regex matches are called
within a loop (like if or for). E.g.
for(int i = 0; i < 10; i++)
{
Regex r = new Regex();
|
by: James |
last post by:
The following code will create memory leaks!!!
using System;
using System.Diagnostics;
using System.Data;
using System.Data.SqlClient;
namespace MemoryLeak
|
by: Adrian |
last post by:
Hi
I have a JS program that runs localy (under IE6 only) on a PC but it has
a memory leak (probably the known MS one!)
What applications are there that I could use to look at the memory usage of
each object within my JS app to help locate my problem?
Thanks
| |
by: Salvador |
last post by:
Hi,
I am using WMI to gather information about different computers (using win2K
and win 2K3), checking common classes and also WMI load balance. My
application runs every 1 minute and reports the status of the machines.
Upon we follow the .NET object lifetime recommendations the application is
constantly consuming more memory! The problem is on the
ManagementObjectSearch, upon we Dispose the object it seems that is not
releasing the...
|
by: Jim Land |
last post by:
Jack Slocum claims here
http://www.jackslocum.com/yui/2006/10/02/3-easy-steps-to-avoid-javascript-
memory-leaks/
that "almost every site you visit that uses JavaScript is leaking memory".
Anybody know anything about this?
Does *Javascript* leak memeory, or
does the *browser* leak memory?
|
by: Ragnar Agustsson |
last post by:
Hi all
I have been wandering about the best way to sandbox memory leaks in 3rd
party libraries when using them from the .Net framework.
I have a 3rd party library, written in C++, that leaks a lot of memory
but I still had to use it.
1.
After using DLLImport and seeing the memory leak I tried to load and
|
by: Peter |
last post by:
I am using VS2008.
I have a Windows Service application which creates Crystal Reports. This is
a multi theaded application which can run several reports at one time.
My problem - there is a memory leak someplace. I can not detect the memory
leak by running several reports by hand, but when I run tha app as a
servrice and process few hundred reports there is significant memory leak.
The application can consume over 1GB of memory where it...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |