473,385 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Memory Management Problem

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
5 2651

<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
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
<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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Tron Thomas | last post by:
Given the following information about memory management in C++: ----- The c-runtime dynamic memory manager (and most other commercial memory managers) has issues with fragmentation similar to a...
4
by: Franklin Lee | last post by:
Hi All, I use new to allocate some memory,even I doesn't use delete to release them. When my Application exit, OS will release them. Am I right? If I'm right, how about Thread especally on...
17
by: ~Gee | last post by:
Hi Folks! Please see the program below: 1 #include<iostream> 2 #include<list> 3 #include <unistd.h> 4 using namespace std; 5 int main() 6 { 7 {
2
by: DANIEL BEAULIEU J | last post by:
Basically i am a student taking an operating systems course which is c++ intensive. Familiar with Java, and so not so familiar with memory management. Looking for suggestions of exercises or web...
9
by: Mike P | last post by:
I know everything about reference counting and making sure you don't have large objects lying around. I have also profiled my app with multiple tools. I know about the fact GC collects memory but...
3
by: beattie.stuart | last post by:
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...
94
by: smnoff | last post by:
I have searched the internet for malloc and dynamic malloc; however, I still don't know or readily see what is general way to allocate memory to char * variable that I want to assign the substring...
3
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". ...
5
by: kumarmdb2 | last post by:
Hi guys, For last few days we are getting out of private memory error. We have a development environment. We tried to figure out the problem but we believe that it might be related to the OS...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.