Click here to Skip to main content
15,889,909 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there,

I am doing a WPF application. When I am running the application and check for the Memory consumption in TaskManager, it is getting gradual increase when we do some operations. I am messed up whether this is the behavior of WPF controls or I did something wrong.

Let me say an example:
I am having two textboxes that contains some values and two buttons.
When I click one of the button, the value of 1st TextBox copied to another. And on click of another button, the reverse (copying from 2nd to 1st) happens.
On each every click the Memory consumption increases. (The case includes ListBox, etc.,..
Please give me some assistance.

The CS code as follows.

private void button1_Click(object sender, RoutedEventArgs e)
{
ListBoxItem item = (PinnedListBox.SelectedItem as ListBoxItem);
PinnedListBox.Items.Remove(item);
UnPinnedListBox.Items.Add(item);
}

private void button2_Click(object sender, RoutedEventArgs e)
{
ListBoxItem item1 = (UnPinnedListBox.SelectedItem as ListBoxItem);
UnPinnedListBox.Items.Remove(item1);
PinnedListBox.Items.Add(item1);
}

Thanks in advance
Karuppasamy
Posted
Updated 23-Jun-13 19:43pm
v2
Comments
[no name] 21-Jun-13 5:06am    
The task manager lies to you do not trust it.
Assistance with what? No description of an actual problem nor is there any code that demonstrates a problem.....
Karuppasamy P 21-Jun-13 5:55am    
Thanks ThePhantomUpvoter, thanks for your comment, the problem is, I don't know whether I should worry about the Memory consumption increase (showing in TasManager, which lies to me as you told lolz), or else this is the behavior, and I don't need to worry about this. Mr.Johannes gave me some suggestion. That pretty helps me.. Thanks Johannes
[no name] 21-Jun-13 6:07am    
Worry about it when and if it becomes an actual problem.

1 solution

Hi KaruppasamyP,

You can not judge the memory consumption of an .NET application like that. Before going into details try to understand what the GC (GarbageCollector) is doing and how. (In your case most likely you see the behaviour that memory is freed only when needed, maybe it's also recycling some memory...). This is something every .NET developer should know anyway.

In theory memory leaks are also possible with .NET - but your description doesn't sound like a real memory leak.

I once (when I was unexperienced with .NET) got nervouse when doing excessive data presentation from a real time communication (Hardware) on a chart, memory pressure on machine was low (a lot of RAM), so memory was growing to the GB area. But then GC kicked in and memory was freed...

So I think you don't have to worry about a memory leak - but maybe good time to learn something about the inner workings of .NET (and memory management is not such an trivial task as someone may think...)

Kind regards

Johannes
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900