CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Memory leaks

  1. #1
    Join Date
    Oct 2008
    Posts
    1

    Question Memory leaks

    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!!!

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Memory leaks

    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.

  3. #3
    Join Date
    Dec 2007
    Location
    South Africa
    Posts
    263

    Re: Memory leaks

    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.

    Code:
      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

    Code:
    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

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Memory leaks

    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...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured