instance of object never disposed according to profiler

Use this forum for questions on how to use .NET Memory Profiler and how to analyse memory usage.
Post Reply
Yan
Posts: 4
Joined: Thu Nov 25, 2010 8:31 pm

instance of object never disposed according to profiler

Post by Yan » Thu Nov 25, 2010 9:24 pm

I have an application that is running all day long (was converted from vb6 to .net using 3rd party dlls and function).
Throughout the day the application memory usage "from WTM" is increasing up to reaching 800Mb.
I know that the memory usage shown by Task Manager should be look at very slighty as it is very not accurate.
This situation is what brought me to download you very nice application "after reading user comments on different forums".
After executing my application with .NET profiler and opening / closing different form your application seems to suggest that the objects of a form are never released from the memory when the form is closing.

Ex: I have a form that allow the user to do batch of update of 150 records ... throughout the batch 4 query are executed for each records which adds up to 600 live instance. but even when i close the batch form those 150 records are still there altough that function takes only 1.2Mb live bytes. Im very convinced that the components are disposed especially when the form is closing but yet your application seems to say the contrary.

Is it possible that someone could have a look at the log file and maybe give me a hint about how to interpret the data.
I zipped the file to 25Mbit and can easily find a free storage place to put it.

Thanks

Andreas Suurkuusk
Posts: 1028
Joined: Wed Mar 02, 2005 7:53 pm

Re: instance of object never disposed according to profiler

Post by Andreas Suurkuusk » Fri Nov 26, 2010 7:44 am

We can take a look at the session file if you want. If you have a download link, you can give it to us here in the forum, or by sending an e-mail to support@scitech.se. Or you can contact us at support@scitech.se and we will provide you with information on how you can upload the file to us.
Best regards,

Andreas Suurkuusk
SciTech Software AB

Yan
Posts: 4
Joined: Thu Nov 25, 2010 8:31 pm

Re: instance of object never disposed according to profiler

Post by Yan » Fri Nov 26, 2010 1:35 pm

Hello Andrea and thanks for your quick reply.
The file is locate on a temporary file host that will keep it for 14 days.

https://www.yousendit.com/download/cEd2 ... bVZjR0E9PQ

To explain the snapshot that I took,
#1 has only my main form loaded, that one is released on the application exit.
#2 i opened a form that has a datagrid with a list of order "about 650" and i selected 150 of them.
#3 i clicked on the button to ship those 150 orders, it opens a new form that shows the first order the 149 other are in queue.
#4 I clicked on the button to process the 150 records, each of them go through different function before being shipped.
#5 I closed the shipping window thus returning to the order form that was never closed, no refresh was done on the datagrid info yet neither to remove the 150 orders.

I think that's pretty much it.

p.s this application was converted from vb6 to .net using a 3rd party software "artinsoft" which is still used mainly to create to get data from the database.
I do know tho that for those specific form the objects are closed and disposed +set to nothing when not used.

Thank you for you help in advance.

Yan
Posts: 4
Joined: Thu Nov 25, 2010 8:31 pm

Re: instance of object never disposed according to profiler

Post by Yan » Fri Nov 26, 2010 1:46 pm

just realised the explanation for the snapshot wasn't accurate.

#3 After the button to ship the item was press, the new shipping window is open at that time with the 150 records. "the order form is still open".
#4 After the modification for the 150 records were applied, still in the shipping window.
#5 Shipping form is closed, back to the order form "the order form was never closed nor refresh through the steps 2 to 5".

Andreas Suurkuusk
Posts: 1028
Joined: Wed Mar 02, 2005 7:53 pm

Re: instance of object never disposed according to profiler

Post by Andreas Suurkuusk » Sun Nov 28, 2010 10:33 pm

When analysing a profiling session it is always good if you have two snapshots that are created before and after a well defined task, preferably a task that should not consume any memory when it is finished, and the application should be in the same state before and after the task. From your snapshot description, I believe that snapshots 2 and 5 are a good candidate pair for analysis. When snapshot 5 is collected, the application should be in the same state as when snapshot 2 was collected. Is that correct?

Anyway, when comparing snapshot 2 and 5, the top issue presenter by the memory analyser is: "Disposed instance with direct EventHandler roots". This issue is often an indication of a memory leak caused by a forgotten EventHandler. In this case the class ADORecordSetHelper has a lot of disposed instances that are kept alive by the SQLConnection.StateChanged event. Actually all ADORecordSetHelper instances have the same shortest root path:

Code: Select all

System.Data.StateChangeEventHandler._target
System.Object[].[...]
System.Data.StateChangeEventHandler._invocationList
System.Data.SqlClient.SqlConnection._stateChangeEventHandler
TOFU.clsDB.mConDB
TOFU.modGlobal.DBconn
ADORecordSetHelper.png
ADORecordSetHelper
ADORecordSetHelper.png (128.22 KiB) Viewed 9503 times
This clearly indicates that the StateChanged event handler is not removed correctly. The allocation call stack of the event handler reveals how it is added:

Code: Select all

Artinsoft.VB6.DB!Artinsoft.VB6.DB.ADO.ADORecordSetHelper.set_ActiveConnection( DbConnection ) ADORecordSetHelper.cs
Artinsoft.VB6.DB!Artinsoft.VB6.DB.RecordSetHelper.Open( bool ) RecordSetHelper.cs
Artinsoft.VB6.DB!Artinsoft.VB6.DB.ADO.ADORecordSetHelper.Open( bool ) ADORecordSetHelper.cs
Artinsoft.VB6.DB!Artinsoft.VB6.DB.RecordSetHelper.Open() RecordSetHelper.cs
Artinsoft.VB6.DB!Artinsoft.VB6.DB.ADO.ADORecordSetHelper.Open( LockTypeEnum ) ADORecordSetHelper.cs
Artinsoft.VB6.DB!Artinsoft.VB6.DB.ADO.ADORecordSetHelper.Open( DbCommand,LockTypeEnum ) ADORecordSetHelper.cs
TOFU!TOFU.clsDB.ExecQuery( string,LockTypeEnum,CursorLocationEnum ) clsDB.vb
TOFU!TOFU.frmOrdersListing.LoadOrders() frmOrdersListing.vb
[Truncated]
So when an active connection is assigned to the record set helper, a StateChanged event is added to the connection, but apparantly this is not removed when the helper is disposed, which causes the memory leak. If you remove the event handler, this leak will be fixed. I have not investigated the session file further, but this is clearly the main memory problem you have. The single SQLConnection instance in the application has 25M held bytes, out of the total 28MB.

After re-reading your post, I realized that ADORecordSetHelper is not developed by you, which makes it a bit harder to make sure that the event handler is correctly removed. Hopefully you can contact ArtinSoft so that they can correct the issue, otherwise you might have to solve it using reflection.
Best regards,

Andreas Suurkuusk
SciTech Software AB

Yan
Posts: 4
Joined: Thu Nov 25, 2010 8:31 pm

Re: instance of object never disposed according to profiler

Post by Yan » Mon Nov 29, 2010 1:37 pm

Andreas

Thankyou for your reply again,
This would explain why the memory usage keeps increasing when the user keep calling the form.
RecordsetHelper is indeed a third party software, but one of the requirement to use it was to have access to the source code instead of a dll library so that we can modify everything.
After i started to use your application i checked to make sure that the recordset were indeed closed, disposed and set to nothing "in vb debugger" and it look like it was so i figured the memory should have been disposed but never tough i had to check something else around it as it clearly was disposed to me.

I will look around the new information your brought to light and keep you update.

Again thank you very much for your help.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 41 guests