By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,962 Members | 2,545 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,962 IT Pros & Developers. It's quick & easy.

Memory Management Problem

P: n/a
I've got a Windows Service written in C# that is having some
unfortunate memory issues. I've been working with .NET MemProfiler and
AllocationProfiler. But you don't have to use those programs to notice
the memory leak. The memory usage in the TaskManager for the process
can be seen climbing and climbing, MBs at a time.

When using MemProfiler, I noticed the Win32 Heap is what seems to be
growing. I've been searching on the internet for Win32 Heap references
but I haven't found much. So what I'm asking is does anyone have some
links to explain on a .NET service interacts with this heap and why it
would get so large?

As a side note, MemProfilers is also reporting that my String instances
are the most troublesome. I'm using them like I would in a regular
application, nothing unordinary. Could some of my memory issues be
related to the timer_elasped event which might be hold reference to my
objects? I don't dispose the timer because, well, I kinda need it ;)

Thanks for any help.

Also, I'm using the WMI a lot. I've heard memory leaks have been
associated with the Management Object but also can't find anything
really on this.

*Really sorry if this is a double post*

Sep 28 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a

<Ro**********@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
| I've got a Windows Service written in C# that is having some
| unfortunate memory issues. I've been working with .NET MemProfiler and
| AllocationProfiler. But you don't have to use those programs to notice
| the memory leak. The memory usage in the TaskManager for the process
| can be seen climbing and climbing, MBs at a time.
|

Note that you should use perfmon to monitor memory consumption.

| When using MemProfiler, I noticed the Win32 Heap is what seems to be
| growing. I've been searching on the internet for Win32 Heap references
| but I haven't found much. So what I'm asking is does anyone have some
| links to explain on a .NET service interacts with this heap and why it
| would get so large?
|

Services are just like any other managed applications, they don't interact
with the managed heap in a different fashion.
Probably your memory consumption relates to unmanaged heap growth, again use
the perfmon and watch your managed (Gen0, 1 and 2) GC heap counters.
| As a side note, MemProfilers is also reporting that my String instances
| are the most troublesome.

What exactly do you mean with troublesome?

I'm using them like I would in a regular
| application, nothing unordinary.

So, they are troublesome too?

Could some of my memory issues be
| related to the timer_elasped event which might be hold reference to my
| objects? I don't dispose the timer because, well, I kinda need it ;)
|
| Thanks for any help.
|
| Also, I'm using the WMI a lot. I've heard memory leaks have been
| associated with the Management Object but also can't find anything
| really on this.
|
If this is the cause of the leak, you should be able to identify them with
the profiler, right?.
What kind if WMI objects are you using in your code, do you dispose the
Management objects when done?
Do you connect to external system?
What version of the framework are you running?

Really sorry for the large amount of questions, but we can't help you
without your answers :-)

Willy.
Sep 28 '06 #2

P: n/a
Thanks for your input, everyone. I've reviewed all your posts and will
now apply some of your thoughts to my problem. To quickly answer, yes
I am using the SciTech Mem Profiler. It's been some help but I'm also
trying out the perfmon to look at my heaps.

I am using Management Objects and I do dispose everything. I have a
custom made class that I use to fill with data and serialize to an XML
file. I also do de-serialization as well further on in the service.
All my streams are disposed using the Close() method.

Without going into to much detail, I have a global declaration of my
custom class. The service then will invoke a method that will then
create a new instance of it using MyClass mc = new MyClass(). After
the service has worked with the class, I then set it to null which as I
thought would tell the GC that this is ready to be collected. But with
the MemProfiler, I see the instances of this class increasing every
timer elasped event. So obviously it's not getting cleaned up because
there is a reference somewhere. Possibly with that global declaration?

Again I will apply everyone's thoughts to the best that I can and
hopefully have something a bit more clear. Thanks again for looking
and helping!

Willy Denoyette [MVP] wrote:
<Ro**********@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
| I've got a Windows Service written in C# that is having some
| unfortunate memory issues. I've been working with .NET MemProfiler and
| AllocationProfiler. But you don't have to use those programs to notice
| the memory leak. The memory usage in the TaskManager for the process
| can be seen climbing and climbing, MBs at a time.
|

Note that you should use perfmon to monitor memory consumption.

| When using MemProfiler, I noticed the Win32 Heap is what seems to be
| growing. I've been searching on the internet for Win32 Heap references
| but I haven't found much. So what I'm asking is does anyone have some
| links to explain on a .NET service interacts with this heap and why it
| would get so large?
|

Services are just like any other managed applications, they don't interact
with the managed heap in a different fashion.
Probably your memory consumption relates to unmanaged heap growth, again use
the perfmon and watch your managed (Gen0, 1 and 2) GC heap counters.
| As a side note, MemProfilers is also reporting that my String instances
| are the most troublesome.

What exactly do you mean with troublesome?

I'm using them like I would in a regular
| application, nothing unordinary.

So, they are troublesome too?

Could some of my memory issues be
| related to the timer_elasped event which might be hold reference to my
| objects? I don't dispose the timer because, well, I kinda need it ;)
|
| Thanks for any help.
|
| Also, I'm using the WMI a lot. I've heard memory leaks have been
| associated with the Management Object but also can't find anything
| really on this.
|
If this is the cause of the leak, you should be able to identify them with
the profiler, right?.
What kind if WMI objects are you using in your code, do you dispose the
Management objects when done?
Do you connect to external system?
What version of the framework are you running?

Really sorry for the large amount of questions, but we can't help you
without your answers :-)

Willy.
Sep 29 '06 #3

P: n/a
<Ro**********@gmail.comwrote:
Without going into to much detail, I have a global declaration of my
custom class. The service then will invoke a method that will then
create a new instance of it using MyClass mc = new MyClass(). After
the service has worked with the class, I then set it to null which as I
thought would tell the GC that this is ready to be collected. But with
the MemProfiler, I see the instances of this class increasing every
timer elasped event.
The Scitech Profiler is ideal for tracking this down.

On the initial screen, double-click on one of the instances that should be
"gone". This will take you to the next tab, and here you can look at the
root paths for the object. This will tell you *exactly* who is still holding
references to it. Eliminate these references, and you're good to go.
Possibly with that global declaration?
Depends on how you implemented it.

For me, in C#, I've had a number of problems like that that all boiled down
to me registering an event handler, and then not removing it. Because the
event handler stayed registered, the instance it was referring to stayed
around forever and we leaked memory like a sieve.

--
Chris Mullins, MCSD.NET, MCPD:Enterprise
http://www.coversant.net/blogs/cmullins
Sep 29 '06 #4

P: n/a
Ok, I was able to iron out the memory leak caused by my own personal
class. MemProfiler is reporting that my string instances,
IdentifierChangedEventHandler and other various System instances
(System.Management, System.Collections, etc) are not getting cleaned
up. So i've got some more work to do. But I've got a better idea how
to work with MemProfiler so thank you for that.
Chris Mullins wrote:
<Ro**********@gmail.comwrote:
Without going into to much detail, I have a global declaration of my
custom class. The service then will invoke a method that will then
create a new instance of it using MyClass mc = new MyClass(). After
the service has worked with the class, I then set it to null which as I
thought would tell the GC that this is ready to be collected. But with
the MemProfiler, I see the instances of this class increasing every
timer elasped event.

The Scitech Profiler is ideal for tracking this down.

On the initial screen, double-click on one of the instances that should be
"gone". This will take you to the next tab, and here you can look at the
root paths for the object. This will tell you *exactly* who is still holding
references to it. Eliminate these references, and you're good to go.
Possibly with that global declaration?

Depends on how you implemented it.

For me, in C#, I've had a number of problems like that that all boiled down
to me registering an event handler, and then not removing it. Because the
event handler stayed registered, the instance it was referring to stayed
around forever and we leaked memory like a sieve.

--
Chris Mullins, MCSD.NET, MCPD:Enterprise
http://www.coversant.net/blogs/cmullins
Sep 29 '06 #5

P: n/a
Well, I've tried over and over and cannot reduce my string instance
count. It's like it never gets collected. I hope Monday goes a little
better. If anyone has experience with string instances and them not
being GCed, please let me know.
Ro**********@gmail.com wrote:
Ok, I was able to iron out the memory leak caused by my own personal
class. MemProfiler is reporting that my string instances,
IdentifierChangedEventHandler and other various System instances
(System.Management, System.Collections, etc) are not getting cleaned
up. So i've got some more work to do. But I've got a better idea how
to work with MemProfiler so thank you for that.
Chris Mullins wrote:
<Ro**********@gmail.comwrote:
Without going into to much detail, I have a global declaration of my
custom class. The service then will invoke a method that will then
create a new instance of it using MyClass mc = new MyClass(). After
the service has worked with the class, I then set it to null which as I
thought would tell the GC that this is ready to be collected. But with
the MemProfiler, I see the instances of this class increasing every
timer elasped event.
The Scitech Profiler is ideal for tracking this down.

On the initial screen, double-click on one of the instances that should be
"gone". This will take you to the next tab, and here you can look at the
root paths for the object. This will tell you *exactly* who is still holding
references to it. Eliminate these references, and you're good to go.
Possibly with that global declaration?
Depends on how you implemented it.

For me, in C#, I've had a number of problems like that that all boiled down
to me registering an event handler, and then not removing it. Because the
event handler stayed registered, the instance it was referring to stayed
around forever and we leaked memory like a sieve.

--
Chris Mullins, MCSD.NET, MCPD:Enterprise
http://www.coversant.net/blogs/cmullins
Sep 29 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.