|
I'm setting all my variables to null in my dispose method but it doesnt seem to work!!! The memory usage of the program does not go smaller, rather, the huge amount of memory is maintained! Why is it so?
Thanks very much!
|
|
|
|
|
Dispose is generally for unmanaged resources.
If you set all variables to null the garbage collector will eventually pick them up during one of the cleanup rounds. This may take a while though, this is why you dont notice anything when you set them to null.
WM.
What about weapons of mass-construction?
|
|
|
|
|
WillemM wrote: If you set all variables to null the garbage collector will eventually pick them up during one of the cleanup rounds.
This is an old myth carried over from Java. In C#, you don't need to set your variable to null in order for the GC to collect them. They will be collected when there's no more references to them, regardless of their null status.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Messianic Instrumentals (with audio)
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
I bet you're looking at Task Manager for this.
You're assuming that the numbers you see in Task Manager is how much memory your app is using. You're not.
The simplified version of what's happening...
What you are seeing is how much memory the Common Language Runtime that your app is running in (a virtual machine, just like any Java app) is using. This includes memory reserved for future allocations but not yet used by, or just freed by, your app. This is known as the Managed Heap. Memory requested by your application is allocated in the Managed Heap, and when freed by your app, is returned to the Managed Heap, not Windows.
The CLR maintains the Managed Heap and, using a self-tuning process, adjusts its size based on what your application has done in the past. If the CLR suspects your app will make large allocations in the near future, it'll maintain a larger Managed Heap, requesting more memory from Windows to do so. If it feels that it doesn't need as much memory in reserve, it'll release some of the Managed Heap memory back to Windows. Or, if Windows wants it back, it'll free up what it can and let Windows have whatever memory the CLR can free up from the Managed Heap.
SO, what you're seeing in Task Manager is not how much memory your application is using, but is how much memory the CLR Virtual Machine is using and has reserved for your app.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
You don't need to use dispose; dispose isn't for cleaning up memory. It's for cleaning up unmanaged resources like socket connections, database connections, file streams, etc.
Each object in your program will be garbage collected when there are no more references to the object. And even then, it won't be collected until the garbage collector lazily comes along and cleans up (or if you force a collection via GC.Collect() )
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Messianic Instrumentals (with audio)
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
The other major thing dispose cleans up are handles. With each control on a form having one, old forms are a prime candidate for disposal.
|
|
|
|
|
please send sample code for .net remoting concept in c#.net
|
|
|
|
|
Please read the How to get answers thread at the top of this forum
Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
There are plenty of sample, here and elsewhere, try doing a search and reading them first, then if you have a specific question ask and we will try to help you.
only two letters away from being an asset
|
|
|
|
|
Feel like a broken record yet, Mark? Kids these days...
|
|
|
|
|
I should just change my signature line and post an empty message
only two letters away from being an asset
|
|
|
|
|
Mark Nischalke wrote: I should just change my signature line and post an empty message
ROTF!
|
|
|
|
|
Hi guys,
In C#, is there a way to get a date that is unchangeable by the user?
Please help!
sasa
|
|
|
|
|
From the system? No.
You could fetch one from the internet (which surely means some sort of open connection to it needs to be open).
|
|
|
|
|
Even that's not foolproof. If a user wanted to mess with your datechecking app, they could use a packet sniffer/modification tool to intecept the NTP request and spoof the return results.
|
|
|
|
|
A combination of this with some sort of encryption could help.
But you are right. It would be really hard to get this working under all circumstances.
A better way (although also not exact) would be to analyze app startup/shutdown along with the system up times to discover manipulations.
|
|
|
|
|
Thank you guys for all your suggestions, I think I will go with the date that I am parsing with my first transaction since nobody is going to go in there and change the date on that. And as for a fixed date I will just hard code the date of install on the application. I think this is the easiest solution for me.
sasa
|
|
|
|
|
I am using .net2005
Is there any documentation tool exist in c#.net?
I want to do technical documentation of project(for developer) such as classess ,namespaces in that project.
|
|
|
|
|
Look at my reply[^] on another thread.
|
|
|
|
|
I want to store value of some variables like userid and password throughout my application .Is there any file in c#.net like Global.asax in ASP.net?
|
|
|
|
|
Look three threads further down.
---
b { font-weight: normal; }
|
|
|
|
|
|
Hi,
I want to dynamicaly load text from an generic data container into a TextBox (Windows Form). How do I put the text/data into the TextBox?
Cheers
/Christoffer
|
|
|
|
|
Hi,
Not quite sure if i understand your query.
Do you want to load a text box with the contents of a text file?
|
|
|
|
|
<br />
Binding binding = new Binding("Text", ds, "MyTable.MyColumn");<br />
Textbox txt = new Textbox();<br />
txt.DataBindings.Add(binding); <br />
only two letters away from being an asset
|
|
|
|
|
Thanx Mark!
That was what I were searching for.
cheers
/Christoffer
|
|
|
|