473,508 Members | 2,210 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Memory leak in WMI

I think I've found a memory leak trying to use the
system.management.ManagementObject, but it could be my programming
skills so I'd appreciate some advice. I've writing a monitoring routine
that queries WMI for some stats, but it continually eats into memory.
I've cut the code down to the following sample but the problem is still
there:

Imports System
Imports System.Management

Module Module1
Private mObjectCpu As ManagementObject

Sub Main()
Dim Counter As Int32
While Counter < 10000
mObjectCpu = New
ManagementObject("Win32_PerfRawData_PerfOS_Process or.Name='_Total'")
mObjectCpu.Get()
mObjectCpu.Dispose()
Counter += 1
End While
End Sub

End Module

I've used the .Net Memory Profiler from Scitech and it's showing a load
of undisposed instances of the object
System.Management.IWbemClassObjectFreeThreaded, but I don't have
references to it in my code, and I can't find anything about it in
MSDN.
Does anyone have any ideas what I've done wrong, or has anyone seen
this kind of problem before?

Cheers,
Stu

Nov 21 '05 #1
3 4557

| Imports System
| Imports System.Management
|
| Module Module1
| Private mObjectCpu As ManagementObject
|
| Sub Main()
| Dim Counter As Int32
| While Counter < 10000
| mObjectCpu = New
| ManagementObject("Win32_PerfRawData_PerfOS_Process or.Name='_Total'")
| mObjectCpu.Get()
| mObjectCpu.Dispose()
| Counter += 1
| End While
| End Sub
|
| End Module

will this work as well if you create the mobjectcpu outside of the while
loop and simply .get() w/n the loop and finally dispose it as you exit the
sub main? what is it that this function is trying to accomplish?

that may not address the memory leak...but it may slow it to a trickle.

hth,

me
Nov 21 '05 #2
Try and dispose the management object after use inside the loop. You are
basically creating objects in a loop, which means 10000 objects will be
created and these will be deallocated only when the GC next runs. A dispose
call will atleast free up the unmanaged resources that are there.

I would expect the memory to go up till some threshold triggers teh GC. My
guess is that a dispose call may clear your problem.

--
Rgds,
Anand
VB.NET MVP
http://www.dotnetindia.com
"be************@gmail.com" wrote:
I think I've found a memory leak trying to use the
system.management.ManagementObject, but it could be my programming
skills so I'd appreciate some advice. I've writing a monitoring routine
that queries WMI for some stats, but it continually eats into memory.
I've cut the code down to the following sample but the problem is still
there:

Imports System
Imports System.Management

Module Module1
Private mObjectCpu As ManagementObject

Sub Main()
Dim Counter As Int32
While Counter < 10000
mObjectCpu = New
ManagementObject("Win32_PerfRawData_PerfOS_Process or.Name='_Total'")
mObjectCpu.Get()
mObjectCpu.Dispose()
Counter += 1
End While
End Sub

End Module

I've used the .Net Memory Profiler from Scitech and it's showing a load
of undisposed instances of the object
System.Management.IWbemClassObjectFreeThreaded, but I don't have
references to it in my code, and I can't find anything about it in
MSDN.
Does anyone have any ideas what I've done wrong, or has anyone seen
this kind of problem before?

Cheers,
Stu

Nov 21 '05 #3
Stu
Sorry for not mentioning it, but I'd had a look at moving the creation
and disposal of the ManagementObject outside of the loop and it doesn't
have any affect. It appears to the be when I call the Get method, under
the hood it carries out some call to unmanaged code and creates some
sort of object (the IWbemClassOb*jectFreeThreaded) which it then
doesn't dispose of properly.
I'm getting this information from the Memory Profiler app, and it's
showing that in the original example the ManagementObject was being
created and disposed of properly. If it helps anyone (cos this is
getting out of my depth) it shows the instance of the
IWbemClassOb*jectFreeThreaded has a call stack of:
MarshalWbemObject.MarshalNativeToManaged(IntPtr)
ManagementObject.Get()
Module1.Main()
And this is the same for each of the several throusand instances of
IWbemClassOb*jectFreeThreaded.
I'm thinking if I could get some sort of handle on that object I could
try and dispose of it myself, but I'm not sure where to start?

Cheers,
Stu

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
3394
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 ? ...
17
4770
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...
4
6056
by: Don Nell | last post by:
Hello Why is there a memory leak when this code is executed. for(;;) { ManagementScope scope = new ManagementScope(); scope.Options.Username="username"; scope.Options.Password="password";...
20
8025
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...
23
4509
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
8
8521
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...
7
6914
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...
3
5292
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". ...
7
15673
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...
22
9303
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...
0
7231
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7336
Oralloy
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,...
0
7401
jinu1996
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...
1
7063
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...
0
7504
tracyyun
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...
1
5059
isladogs
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...
0
4720
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...
0
1568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.