Advice needed for objects that are persisting...

Use this forum for questions on how to use .NET Memory Profiler and how to analyse memory usage.
Post Reply
Simon Lockington
Posts: 5
Joined: Mon Jul 10, 2006 4:31 am

Advice needed for objects that are persisting...

Post by Simon Lockington » Mon Jul 10, 2006 6:08 am

Hello there,
First of all, I think your software is great, it has helped me solve a number of memory related issues with various projects already. It's a very cost effective tool!

However I need a little advice with an issue I have now. I have been using your tool on this project and have successfully fixed a couple of leaks, however this last one eludes me.

In this instance, I pass a class made up of 'string' variables to a third party COM object that does some processing on this class and when done, raises an event and passes the class back in the event.

I was going to use a 'Struct' instead of a class but the COM object didn't seem to like that.

Once the class is returned, I'm setting it to Nothing once I'm finished with it. However, it never shows up as 'Removed' in your software. The system continues to create new instances of objects as normal, but they are never destroyed.

I use your software to see if there are any 'References' record, but that list only contains '<root>'.
There are no entries in the Root Path either.

I believe the COM object (which I have no code control over) is maintaining some kind of reference to the class that I cannot see which is why the class is not being garbage collected.

Here is the makeup of the class being passed in, as you can see, it's very simple:

Public Class Program
Public ProgramDateTime As DateTime
Public ProgramName As String
Public HD As Boolean
Public Classification As String
Public ClosedCaption As Boolean
Public Heading As String
Public Synopsis As String
Public IsRollHeading As Boolean
Private intLoopCount As Integer
Public ReadOnly Property LoopCount() As Integer
Get
Return intLoopCount
End Get
End Property
Public Sub IncrementLoopCount()
intLoopCount = intLoopCount + 1
End Sub
End Class

Any ideas you could provide as to where I could start looking, I'd really appreciate.

Thank you for your time.

Simon

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

Post by Andreas Suurkuusk » Wed Jul 12, 2006 7:34 am

From the information you have provided I'm not able to explain why your instance is not GCed. There are several types of root references that cannot be identified, such as GC handles, pinned instances, temporary variables etc. When dealing with interop (COM or P/Invoke), it is possible that some instances get pinned. However, they should become unpinned when the method call returns. Furthermore, only blittable instances will be pinned, and your class is not blittable.

So, I don't see how your COM object could be keeping a reference to your instance. Can you provide some additional information about this problem (allocation call stacks, some more code, etc)?
Best regards,

Andreas Suurkuusk
SciTech Software AB

Simon Lockington
Posts: 5
Joined: Mon Jul 10, 2006 4:31 am

Post by Simon Lockington » Wed Jul 12, 2006 8:24 am

Hi Andreas,
Thank you for your reply. The following is some code snippets that may be of help?

This Sub adds the 'Program' class to the third party COM based object (rtxRoll being that object).

Private Sub AddNextRollItem()

' Get next program
If prgCurrentProgram Is Nothing Then
Try
prgCurrentProgram = CH10EPG.prgManager.GetRollProgram
Catch ex As Exception
ErrorDel.Invoke("An error occured preparing the roll", ex, EventLogEntryType.Error)
Exit Sub
End Try
End If

If prgCurrentProgram Is Nothing Then
Exit Sub
End If

Dim newRollItem As RollItem

If RollHeading(prgCurrentProgram).ProgramName <> strCurrentRollHeading Then
strCurrentRollHeading = RollHeading(prgCurrentProgram).ProgramName
newRollItem = New RollItem(rtx, rtxGlobCon, rtxLYTRollItem, CInt(dblWidth), RollHeading(prgCurrentProgram))
Else
newRollItem = New RollItem(rtx, rtxGlobCon, rtxLYTRollItem, CInt(dblWidth), prgCurrentProgram)
prgCurrentProgram = Nothing
End If

' Add to roll.
rtxRoll.AddItem(newRollItem.RollData, newRollItem.ProgramDetails)
newRollItem.Dispose()
newRollItem = Nothing

End Sub

The following is the routine used when rtxRoll raises an offscreen event:

Private Sub rtxRoll_ItemOffScreen(ByRef Notification As Object) Handles rtxRoll.ItemOffScreen

rtxRoll.RemoveItem()

If booRollPause = False Then

booRollPause = True
Try
If intRollPause <> 0 Then
If rtxRoll.Status = RtxLib.EffectStatus.Paused_es Then
' The effect is already paused cause RTX cannot keep up, skip.
Exit Sub
End If

rtxRoll.Pause()

rollTimer.Interval = intRollPause
rollTimer.Start()
End If

' Check to see if the program has a synopsis. If it does, show it.
If Not CType(Notification, Program).Synopsis Is Nothing Then
If CType(Notification, Program).Synopsis.Length > 0 Then
If rtxRoll.Status <> RtxLib.EffectStatus.Paused_es Then
rtxRoll.Pause()
End If
SynopsisManager.ShowSynopsis(CType(Notification, Program))
Thread.Sleep(500)
rtxRoll.Resume()
End If
End If

Notification = Nothing

AddNextRollItem()
Catch ex As Exception
ErrorDel.Invoke("An error occured during the offscreen event of the roll", ex, EventLogEntryType.Error)
Finally
booRollPause = False
End Try
Else
Exit Sub
End If

End Sub

Basically, when an offscreen event is triggered, a call is made to AddNextRollItem to create a new 'Program' and add it to the rtxRoll object.

I have a Profiler Session available that I just captured and have emailed to support@scitech.se that may be able to shed some light?

Thank you very much for your time.

Simon

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

Post by Andreas Suurkuusk » Mon Jul 17, 2006 12:22 pm

Hi,

I have looked at the code and the session file you provided, but I have not been able to come up with an explanation for the <root> that references your Program instances.

I recommend that you try to locate the problem by reducing the code that is using the Program instances. If you manage to find the section of code that causes the <root> to reference your Program instance, you will probably get a better idea what's causing the problem.
Best regards,

Andreas Suurkuusk
SciTech Software AB

Post Reply

Who is online

Users browsing this forum: No registered users and 21 guests