Click to See Complete Forum and Search --> : Memory leaks


amolkumbhar
October 15th, 2008, 04:59 AM
Hi ,
I am working in s/w company where i am working on vb.net.
We have developed one desktop application which is running 24*7 at client side.
We are running it by using scheduler. As it is running 24*7, it get crashed after 3 to 4 days.
And we came to know that it is bcoz of the memory leak in dotnet.
1)One of the cause we detected is, we are using dataset while filling the dataset using OledbDataAdapter, it creates DataColumn object implicitly. and the memory created for DataColumn is not getting freed.
2)Another thing is we are using ATL COM dll in Vb.net. and we are creating object of class in that COM dll by using "new" operator.
but we are not sure that the memory created for that object is getting freed or not.

And there are many more things which are causing the memory leak.

And bcoz of all this "system.stackOverFlowException" is getting displayed while running 24*7.
When we debug this application exception come where we have created COM object and called one of its function.

Plz let me know the solution if any.
Thanks in Advance!!!

DataMiser
October 15th, 2008, 12:35 PM
You need to free up memory when you are done with it. It you create an object and do not free it then create it again you will run out of memory in even a simple app after it runs long enough.


Most likely the memory leak is created by your code.

vuyiswam
October 16th, 2008, 12:41 PM
Really what DataMiser wrote is true, that is a reason i dont like vb.net, you can create an object and never use it or reference it, it will not complain. Now when dealing with dataset you have to be careful with your connections and your objects. i once had an application that got a similar error as your "out of memory" ,the reason is that i have declared form objects and never use them , and they filled the memory and it blew up. Now you need to go to your code and start to get rid of unnecessary memory creation. When you do your database in your data layer, do the following.


SqlConnection con = new(strcon);

try
{
datadapter.Fill(DataSet, "mytable");
}
catch(SqlException e)
{

finally
{

con.Close();
}

When it comes to your object that you reference, I mean the dll, you need not to worry about that Garbage Collector willtake care of that , but this does not give you a right to do the following


MyClass obj ;

Try
{
Obj= new MyClass();
}


If you have shown us your code, we would have pointed out the leaks, just look at the point I raised and check you code , if there is something you don’t understand, post your code

Hope this Helps

HanneSThEGreaT
October 23rd, 2008, 07:47 AM
VB.NET doesn't create Memory Leaks, your code caused it.
We can assume all we want,
We can advise all we want,
But, the fact remains that we'll have to see your code.
Proper disposal of objects etc. should be second nature...