Memory problem

  • Thread starter Thread starter Nikolay Petrov
  • Start date Start date
N

Nikolay Petrov

I've got this issue:
When I start my application it takes a lot of memory. I guess this is caused
by CLR.
That's fine. But every time the app performs an action (open new form, load
data in dataset, something, it doesn't matter) the memory used by the
application increases. After using it half an hour it grows so big that most
of PCs here act very slowly.

Is this behavior caused somehow by my lack of programming knowledge or
something else?
 
I've got this issue:
When I start my application it takes a lot of memory. I guess this is caused
by CLR.
That's fine. But every time the app performs an action (open new form, load
data in dataset, something, it doesn't matter) the memory used by the
application increases. After using it half an hour it grows so big that most
of PCs here act very slowly.

Is this behavior caused somehow by my lack of programming knowledge or
something else?

It sounds like a resource leak - if the memory is not being released.
What version of the framework are you using? I know in 1.0 (pre-sp1, I
think) there was a memory leak caused by runtime when dealing with large
objects. I've also seen reference to some other mem leak bugs in the
framework - but they seem a little obscure... I would make sure that
you are releasing all references to module level objects and that you
are calling Dispose on any objects that implement IDisposable.
 
What are you using to see this memory leak.

Task manager is not a good indicator.
 
I am using task manager to watch the memory usage.
Also I am using .NET Framework 1.1 SP1 - latest
And I don't think it is a memory leak or something?
Even on simpliest app with a two forms and a button where it is used to open
the second form. nothing else in the app I see this behavior.
I am calling the dispose method but it doesn't matter.
 
I am using task manager to watch the memory usage.
Also I am using .NET Framework 1.1 SP1 - latest
And I don't think it is a memory leak or something?
Even on simpliest app with a two forms and a button where it is used to open
the second form. nothing else in the app I see this behavior.
I am calling the dispose method but it doesn't matter.

Nikolay... It sounds like your just observing the affects of windows
memory allocation... It always allocates more to a process then is
necessary to avoid more allocations later on (memory allocations are
expensive). If you minimize your form (before you do anything else) - you
will probably see a decrease in memory usage...
 
You are right, after minimize the app and the maximize it again the memory
usage drop.
But after that things are the same - every click on form controls takes
memory and after some time the memory usage increases significantly. How to
prevent this behavior? I am not going to tell users to minimize thier app
from time to time. It's kind of silly.
 
Nikolay,

The garbage collector collects when it is needed. When you use a form and
two buttons made by the formdesigner than Idisposable is implemented and
there should be no need to use dispose, because that is where Idisposable is
for. That there is memory used should not be of any reason why your program
is going slow, although the gc cleans (in my situation) I have seen even
when there is showed something to the screen.

However when you make by instance a routine like this,
\\\
private frmarray as new arraylist
dim frm as frm
frmarraylist.add(frm)
frm.open
///
You can be sure that this will create a lot of forms and never clean the
memory and the resources until you have removed the form from the arraylist
because it still has a reference.

http://msdn.microsoft.com/architecture/default.aspx?pull=/library/en-us/dnpag/html/scalenet.asp

I hope this gives an idea?

Cor
 
You are right, after minimize the app and the maximize it again the memory
usage drop.
But after that things are the same - every click on form controls takes
memory and after some time the memory usage increases significantly. How to
prevent this behavior? I am not going to tell users to minimize thier app
from time to time. It's kind of silly.

You don't have to... The behavior I was pointing out is not specific to
..NET applications. That is the way windows memory allocation works. A
process when first started is granted a larger working set then it is
expected to be used (to speed up future memory allocations). When the app
is minimized the OS reduces that working set - since the application is no
longer being used by the user.

Now, as for the growing memory... Again, you've got two main forces at
work here. You have the fact that .NET is a gc based system - which means
that memory for objects is not immediately returned to the OS. Objects are
reclaimed during a gc cycle, which is triggered when memory pressure
reaches a certain threashold. The second main factor is again - windows
memory managment. When memory that is being used by an application is
returned to the system - the, system does not necessarily remove it from
the processes working set. Again, this is because the OS figures the
process might want to allocate memory again - so, it can just reuse that
which is already allocated. If the OS needs the memory for other
applications, it will take it...

Basically, what I'm saying is that though, in general .NET apps have a
larger foot - it is not something you should be worrying about unless it is
continuing to grow without bounds and causing applications to crash due to
resource errors - this situation would be a result of a resource leak
(which is usually the result of improper management of unmanaged
resources). And in that case, you would probably want to employ a
profiling tool of some sort to help you locate the cause of the problem.
 
Did everyone else miss what I said. Task manager is a VERY bad tool for
determinng memory allocation within .NET. That's why you have to use the
profiler. .NET Memory profiler is an excellent tool to give accurate
results (as well as see what classes are leaking).

And.. if your using any Component One Controls, thats where your leak
probably is..Because C1 Controls are garbage.

-CJ
 
Hi CJ,

Did I deny that with my text, I could have told it again, however did it
that often and you did that already, when I had not agreed with you I would
have put a friendly message at your message, be not afraid of that.

My message was especially not about the memory, but about the performance
my very dear friend (not sarcastic)).

:-)

Cor
 
Fair enough cor,

I wasn't saying it in anger in any way.. just seemed that some people were
focusing on task manager being a tool to do memory usage off of.

I know your not sarcastic. It's all good. =)
 
Did everyone else miss what I said. Task manager is a VERY bad tool for
determinng memory allocation within .NET. That's why you have to use the
profiler. .NET Memory profiler is an excellent tool to give accurate
results (as well as see what classes are leaking).

And.. if your using any Component One Controls, thats where your leak
probably is..Because C1 Controls are garbage.

-CJ

No... I almost made reference to your post actually - but, I figured it
stood on it's own. You are definately correct. Using the Task Manager
for this kind of profiling is pretty worthless.
 
Hmmm apparently (given this is the second message). I came off a little
angry/crass in my last message.

To everyone, I apologize, wasn't meant to be that way...
 
Hi CJ,

Is it so hard to be married that you even make apologizes to us.

There is already so few fun last times in this newsgroup.

I am glad you kicked it a little bit up.

(I want all the time show you this message I made. It was a discussion if
something what was in C# should be in the same way in VBNet). Kelly found it
a nice one.

http://tinyurl.com/4e57m

:-)

Cor
 

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

Similar Threads


Back
Top