Click here to Skip to main content
15,887,746 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: Visual Studio Online or Express? Pin
Richard MacCutchan12-Aug-14 20:55
mveRichard MacCutchan12-Aug-14 20:55 
GeneralRe: Visual Studio Online or Express? Pin
adamhill913-Aug-14 0:22
adamhill913-Aug-14 0:22 
AnswerRe: Visual Studio Online or Express? Pin
PIEBALDconsult11-Aug-14 8:01
mvePIEBALDconsult11-Aug-14 8:01 
AnswerRe: Visual Studio Online or Express? Pin
Rob Caron MSFT12-Aug-14 7:12
Rob Caron MSFT12-Aug-14 7:12 
GeneralRe: Visual Studio Online or Express? Pin
adamhill913-Aug-14 0:26
adamhill913-Aug-14 0:26 
AnswerRe: Visual Studio Online or Express? Pin
thatraja13-Aug-14 2:30
professionalthatraja13-Aug-14 2:30 
AnswerRe: Visual Studio Online or Express? Pin
sankarsan parida27-Aug-14 20:48
professionalsankarsan parida27-Aug-14 20:48 
QuestionRequesting help chasing a .net memory leak Pin
Joshua Gayou10-Aug-14 7:46
Joshua Gayou10-Aug-14 7:46 
Hey, all. Been after this one a few days and it's driving me crazy. I've refactored several times based on information I've found on the net (i.e. event handlers, circular references, etc) but I'm just not getting anywhere.

What I have is a generic hierarchical data structure that is distributed over a LAN via TCP. The concept was that I wanted to be able to share variables between applications over networked machines using a common protocol. The problem is whenever I run the thing and watch the process with Process Explorer, I can see a steady increase in Physical Memory usage (WS Private). I have a test application that accesses the nodes in the tree several times a second and can watch it climb (app consumes about 50 MB of memory when idle and then climbs at about 300 K per second). By playing around and commenting/uncommenting various blocks of code, I've narrowed the problem down to whenever the nodes in the tree are being accessed. At first I was certain that the problem was in the implementation of my object hierarchy because I had circular references (children had a reference to their parents) and figured that was messing up GC. But then I redid the implementation to remove that relationship and it's still happening. This is really driving me nuts.

Here's some (abridged) code. I can provide more if needed but don't want this to turn into a novel outright.

First, the object hierarchy:

Starts with a MustInherit base class: Node
Node is just a basic node in the tree. Everything that lives in the tree must inherit from this class.

ContainerNode:
Inherits from Node. It has an internal sortable dynamic list of Node instances and includes methods necessary to traverse that list (HasChildren, etc).

Cluster:
Inherits from ContainerNode. A Cluster is a collection of related nodes. A Cluster is the top most object in the tree. A Cluster contains a list of Groups and DataNodes.

Group:
Inherits from ContainerNode. A Group is a collection of related nodes within a Cluster. A Group contains more Groups and DataNodes.

DataNode:
Inherits from Node. A DataNode is a variable "leaf" item on the tree. It can be any kind of basic data type (string, integer, etc, etc).

The whole tree is accessed through a class called Agent. The Agent provides the methods necessary to add and remove nodes and set their values. It also sends changes in the tree out to the network and receives requests from connected clients over the network to modify the tree.

Nodes on the tree each have a signature, which looks pretty similar to a directory path in Linux (/Cluster/Group/Group/DataNode). I don't deal with relative paths.

So after a bunch of screwing around I've traced the problem down to whenever I access a node on the tree. Up at the App level, I have the following:

VB
If (m_Service.NodeValue(Path.ToString & "/ParamID") = ParamType) Then
    Return m_Service.NodeValue(Path.ToString & "/AutoCalc")
End If


This corresponds to a property in a class called Service, which exposes the Agent and everything else to client applications (this whole thing is packed into a class library).

VB
Public Property NodeValue(ByVal Path As String) As Object
    Get
        Return m_Agent.NodeValue(Path)
    End Get
    Set(ByVal value As Object)
        m_Agent.NodeValue(Path) = value
    End Set
End Property


Within Agent, there is the following:
VB
Public Property NodeValue(ByVal Path As String) As Object
    Get
        Try
            Return DirectCast(Me.GetNode(Path), Tree.DataNode).Value
        Catch ex As Exception
            Return Nothing
        End Try
    End Get
    Set(ByVal value As Object)
        Try
            Dim N As DataNode = DirectCast(Me.GetNode(Path), Tree.DataNode)
            If (N IsNot Nothing) Then
                If (N.NodeVal <> value) Then
                    N.NodeVal = value
                    If (Me.SuppressEvents = False) Then
                        OnValueChanged(N.Signature.ToString, value)
                    End If
                End If
            End If
        Catch ex As Exception
        End Try
    End Set
End Property


GetNode does this:
VB
Public Function GetNode(ByVal Path As String) As Node
    If (m_Nodes.IsEmpty) Then
        Return Nothing
    End If

    If (String.IsNullOrEmpty(Path)) Then Return Nothing

    If (Path.Equals("/")) Then
        m_Nodes.First()
        Return m_Nodes.Current
    End If

    If (Path.Substring(0, 1).Equals("/")) Then
        Return AbsolutePath(Path)
    End If

    Return Nothing
End Function

Private Function AbsolutePath(ByVal Path As String) As Node
    Path = Path.TrimStart("/")
    Dim Data() As String = Path.Split("/")

    If (Data.Length > 0) Then
        Dim Index As Integer = m_Nodes.GetItemIndex(New SearchNode(Data(0)))
        AbsolutePath = m_Nodes.AtIndex(Index)

        If ((AbsolutePath IsNot Nothing) And (Data.Length > 1)) Then
            For X As Integer = 1 To Data.Length - 1
                If (AbsolutePath IsNot Nothing) Then
                    If (AbsolutePath.HasChildren) Then
                        AbsolutePath = DirectCast(AbsolutePath, ContainerNode).Child(Data(X))
                    Else
                        Return Nothing
                    End If
                Else
                    Return Nothing
                End If
            Next
        End If

        Return AbsolutePath
    End If

    Return Nothing
End Function


Now, through testing, I've found that calling GetNode is enough to make the memory leak occur. That means no events firing and nothing else special, just a simple GetNode, which returns the Node instance back to the caller.

It seems to me that this should be something that the language should be able to handle, so I'm either missing something fundamental or I'm nowhere near as knowledgeable as I'd like to believe.

I greatly appreciate any help, hints, or insight you can provide.

Thanks much.
AnswerRe: Requesting help chasing a .net memory leak Pin
Eddy Vluggen11-Aug-14 7:51
professionalEddy Vluggen11-Aug-14 7:51 
GeneralRe: Requesting help chasing a .net memory leak Pin
Joshua Gayou11-Aug-14 10:48
Joshua Gayou11-Aug-14 10:48 
AnswerRe: Requesting help chasing a .net memory leak Pin
Joshua Gayou11-Aug-14 13:08
Joshua Gayou11-Aug-14 13:08 
QuestionCS0029: Cannot implicitly convert type 'System.DateTime' to 'var' Pin
demoninside98-Aug-14 20:50
demoninside98-Aug-14 20:50 
AnswerRe: CS0029: Cannot implicitly convert type 'System.DateTime' to 'var' Pin
PIEBALDconsult8-Aug-14 20:56
mvePIEBALDconsult8-Aug-14 20:56 
GeneralRe: CS0029: Cannot implicitly convert type 'System.DateTime' to 'var' Pin
demoninside98-Aug-14 21:13
demoninside98-Aug-14 21:13 
GeneralRe: CS0029: Cannot implicitly convert type 'System.DateTime' to 'var' Pin
PIEBALDconsult9-Aug-14 5:24
mvePIEBALDconsult9-Aug-14 5:24 
GeneralRe: CS0029: Cannot implicitly convert type 'System.DateTime' to 'var' Pin
Dave Kreskowiak9-Aug-14 6:25
mveDave Kreskowiak9-Aug-14 6:25 
GeneralRe: CS0029: Cannot implicitly convert type 'System.DateTime' to 'var' Pin
demoninside98-Aug-14 21:22
demoninside98-Aug-14 21:22 
GeneralRe: CS0029: Cannot implicitly convert type 'System.DateTime' to 'var' Pin
PIEBALDconsult9-Aug-14 5:23
mvePIEBALDconsult9-Aug-14 5:23 
AnswerRe: CS0029: Cannot implicitly convert type 'System.DateTime' to 'var' Pin
Richard MacCutchan8-Aug-14 22:39
mveRichard MacCutchan8-Aug-14 22:39 
GeneralRe: CS0029: Cannot implicitly convert type 'System.DateTime' to 'var' Pin
demoninside99-Aug-14 0:35
demoninside99-Aug-14 0:35 
QuestionRetrieve information from UDL file Pin
Ashfaque Hussain4-Aug-14 19:23
Ashfaque Hussain4-Aug-14 19:23 
AnswerRe: Retrieve information from UDL file Pin
Eddy Vluggen5-Aug-14 2:37
professionalEddy Vluggen5-Aug-14 2:37 
QuestionControls resize to init after changing language Pin
ChriSSi0034-Aug-14 1:36
ChriSSi0034-Aug-14 1:36 
AnswerRe: Control resize to init after changing language Pin
Eddy Vluggen4-Aug-14 2:00
professionalEddy Vluggen4-Aug-14 2:00 
AnswerRe: Control resize to init after changing language Pin
Bernhard Hiller4-Aug-14 20:49
Bernhard Hiller4-Aug-14 20:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.