Memory Leaks

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • SLN

    #1

    Memory Leaks

    Hi,

    Im currently working on a C# appn and facing a problem
    with memory leaks.

    In our application we have a tabcontrol and tabpage
    named "Main" in it. This tabpage has a treeview control
    and upon clicking on any node we create a new tabpage and
    add it to the tabcontrol.

    Currently in our testing we have used the dotnet memory
    profiler to take snapshots before creation of a new tab
    page and after closing it. Ideally speaking, the delta
    should be zero. When we compare the two snapshots we find
    the following objects still remaining in memory.

    Int32, WeakReference, BindingContext. HashKey and String.
    The increase is consistent.

    When i checked the call stack of the above instances, they
    are getting created when a tabpage is added to the
    tabcontrol.
    [color=blue]
    > tabCtrl.TabPage s.Add(new TabPage());[/color]

    we couldn't make out why they are getting created and why
    not getting disposed.

    Request any help on this issue.

    Thanks in Advance,
    Gupta.

  • Peter Koen

    #2
    Re: Memory Leaks

    "SLN" <anonymous@disc ussions.microso ft.com> wrote in news:007401c3a5 ae
    $daa9a7b0$a0012 80a@phx.gbl:
    [color=blue]
    > Hi,[/color]
    [...][color=blue][color=green]
    >> tabCtrl.TabPage s.Add(new TabPage());[/color]
    >
    > we couldn't make out why they are getting created and why
    > not getting disposed.
    >
    > Request any help on this issue.[/color]

    Try calling GC.Collect() before taking the second memory sample. Normaly
    the GC isn'T invoked immediately when you dispose an object. On Dispose
    only unmanaged resources like filehandles get released. Memory is released
    later when the GC is called.


    --
    ------ooo---OOO---ooo------

    Peter Koen - www.kema.at
    MCAD CAI/RS CASE/RS IAT

    ------ooo---OOO---ooo------

    Comment

    • Guest's Avatar

      #3
      Re: Memory Leaks

      Thank you Peter for responding.
      I have the same problem even if i call GC.Collect().
      [color=blue]
      >-----Original Message-----
      >"SLN" <anonymous@disc ussions.microso ft.com> wrote in[/color]
      news:007401c3a5 ae[color=blue]
      >$daa9a7b0$a001 280a@phx.gbl:
      >[color=green]
      >> Hi,[/color]
      >[...][color=green][color=darkred]
      >>> tabCtrl.TabPage s.Add(new TabPage());[/color]
      >>
      >> we couldn't make out why they are getting created and[/color][/color]
      why[color=blue][color=green]
      >> not getting disposed.
      >>
      >> Request any help on this issue.[/color]
      >
      >Try calling GC.Collect() before taking the second memory[/color]
      sample. Normaly[color=blue]
      >the GC isn'T invoked immediately when you dispose an[/color]
      object. On Dispose[color=blue]
      >only unmanaged resources like filehandles get released.[/color]
      Memory is released[color=blue]
      >later when the GC is called.
      >
      >
      >--
      >------ooo---OOO---ooo------
      >
      > Peter Koen - www.kema.at
      > MCAD CAI/RS CASE/RS IAT
      >
      >------ooo---OOO---ooo------
      >.
      >[/color]

      Comment

      • Niall

        #4
        Re: Memory Leaks

        This is because the .Net Memory Profiler already does a full GC (including
        clearing up objects waiting for finalizers) before it does the snapshot.

        For the actual problem... if the objects are not within your control,
        there's not a lot you can do about them. They may be freed during some
        process in the .Net tabcontrol, ie: dispose or adding tabpages, etc. If they
        are still around after you close the form, that's more of a problem.

        Niall

        <anonymous@disc ussions.microso ft.com> wrote in message
        news:01b601c3a5 e5$e3bc7b20$a00 1280a@phx.gbl.. .[color=blue]
        > Thank you Peter for responding.
        > I have the same problem even if i call GC.Collect().
        >[color=green]
        > >-----Original Message-----
        > >"SLN" <anonymous@disc ussions.microso ft.com> wrote in[/color]
        > news:007401c3a5 ae[color=green]
        > >$daa9a7b0$a001 280a@phx.gbl:
        > >[color=darkred]
        > >> Hi,[/color]
        > >[...][color=darkred]
        > >>> tabCtrl.TabPage s.Add(new TabPage());
        > >>
        > >> we couldn't make out why they are getting created and[/color][/color]
        > why[color=green][color=darkred]
        > >> not getting disposed.
        > >>
        > >> Request any help on this issue.[/color]
        > >
        > >Try calling GC.Collect() before taking the second memory[/color]
        > sample. Normaly[color=green]
        > >the GC isn'T invoked immediately when you dispose an[/color]
        > object. On Dispose[color=green]
        > >only unmanaged resources like filehandles get released.[/color]
        > Memory is released[color=green]
        > >later when the GC is called.
        > >
        > >
        > >--
        > >------ooo---OOO---ooo------
        > >
        > > Peter Koen - www.kema.at
        > > MCAD CAI/RS CASE/RS IAT
        > >
        > >------ooo---OOO---ooo------
        > >.
        > >[/color][/color]


        Comment

        Working...