I've been using MemProfiler 3.0 for quite some time now to 'tidy up' a Windows Service application I'm writing. However I need a little help to fix the last remaining problem.
Each time I collect the heap, I have a large number of system.weakreferences which only ever increase with time. After an hour or so of running, I have 3.5mb total bytes allocated to this which corresponds to the increased memory usage of my application over time.
When looking at a number of these instances, they seem to have been created in either webservice calls, or calls to table adapters in a dataset (VB.NET 2.0).
All calls to both the webservices and the table adapters are contained within using statements.
I'm not sure what else I can do to ensure these instances are disposed and removed correctly?
I've tried to do a lot of research on what the system.weakreference object is on the net but come away more confused. I can only assume it is being used by the underlying Framework code and not any I have written myself. However, I can't continue to allow the application's memory usage to continue to grow in size like it does.
Any ideas would be greatly appreciated.
I assume that you have a lot of WeakReferences in your service that are no longer referencing any other instances. In order to find out why the WeakReference instances are not garbage collected, you should investigate the root paths of the instances. You can do this either in the Type details view (where the shortest root paths will be combined) or in the Instance details view (where you will see all root paths for a specific WeakReference instance). If you need more help with investigating this issue, you can post the allocation call stack and one more root paths of the WeakReference instance to this thread. Hopefully I will be able to give you some additional information about why the WeakReference is not GCed.
SciTech Software AB
This problem seems to be the only one I can find with the app now. There are a huge amount of weakreferences generated (1,253 in two minutes).
Looking at a large selection of instances, they seem to have been allocated during the constructor of the WebService object (AutomationService) or a call to one of the table adapters in the OLEDB 2 data access layer.
Do the screen shots help at all?
All Webservice and data access code is contained withing Using Statements which should manage this shouldn't they?
The call stack in the first screenshot shows that the WeakReference is created in the AutomationService constructor. Have you investigated this constructor and seen how the WeakReference is created and used?
The root path shows that the WeakReference has been stored in an ArrayList referenced from the static field __ENCList. This list needs to be periodically purged from left-over WeakReferences (i.e. WeakReferences whose Target is null). The using statement makes sure that the Dispose method is called on disposable instances, but unless the Dispose method performs cleanup of the __ENCList ArrayList, this will not help with the issue you have.
I suggest that you take a look at the tblMatrixTableAdapter class, and try to add code that removes left-over WeakReferences from the __ENCList ArrayList.
SciTech Software AB
Code: Select all
Sub Cleanup__ENCList() If (Not System.Diagnostics.Debugger.IsAttached) ) Then Dim asm As Assembly '= Assembly.GetExecutingAssembly() For Each asm In AppDomain.CurrentDomain.GetAssemblies() For Each type As Type In asm.GetTypes() Dim myFieldInfo As FieldInfo = type.GetField("__ENCList", BindingFlags.NonPublic Or BindingFlags.Static) If Not myFieldInfo Is Nothing Then Dim al As ArrayList = myFieldInfo.GetValue(Nothing) al.Clear() End If Next Next End If End Sub
Users browsing this forum: No registered users and 29 guests