DataSet object not releasing memory

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

    DataSet object not releasing memory

    Hi,

    I'm encountering a strange phenomenon whereby a DataSet object is not
    releasing its memory when it's being disposed and/or set to Nothing.

    It is part of a Windows service written in VB.NET which fetches data out of
    a mySQL database, interrogates each row individually and takes various
    actions accordingly. It can fetch upwards of 300,000 rows, each of which
    vary between 1k and 2k in size, making the resulting DataSet object almost
    500Mb in size. This in itself is not much of a problem, except that when the
    service has finished working with the DataSet, it does not release the
    memory it has been using.

    I'm using it in what appears to me at least to be a fairly standard way
    (code at the end of this post).

    What do I have to do to free up the memory allocated to the DataSet object?
    I've even tried running System.GC.Colle ct(), though that expectedly made no
    difference.

    Any assistance gratefully received.

    Mark Rae


    Option Explicit On
    Option Strict On

    Imports CoreLab.MySql
    Imports System.Collecti ons
    Imports System.Data
    Imports System.Xml

    Public Function Import(pstrMySQ LConnectString As String, pstrSQL As String)
    As Boolean

    Dim objMySQL As New CMySQLCoreLab(p strMySQLConnect String)
    Dim objMySQLDS As DataSet

    objMySQLDS = objMySQL.GetDat aSet(pstrSQL)

    For Each objRow As DataRow in objMySQLDS.Tabl es(0).Rows
    '
    ' do the processing
    '
    Next

    objMySQLDS.Disp ose
    objMySQLDS = Nothing
    objMySQL.Dispos e
    objMySQL = Nothing

    End Function


  • Chad Z. Hower aka Kudzu

    #2
    Re: DataSet object not releasing memory

    "Mark Rae" <mark@mark-N-O-S-P-A-M-rae.co.uk> wrote in
    news:ujdOYKtEFH A.2572@tk2msftn gp13.phx.gbl:[color=blue]
    > I'm encountering a strange phenomenon whereby a DataSet object is not
    > releasing its memory when it's being disposed and/or set to Nothing.[/color]

    How are you measuring this fact? Dispose does not actually free the memory,
    thats up to the GC.


    --
    Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
    "Programmin g is an art form that fights back"

    Develop ASP.NET applications easier and in less time:

    Comment

    • Mark Rae

      #3
      Re: DataSet object not releasing memory

      "Chad Z. Hower aka Kudzu" <cpub@hower.org > wrote in message
      news:Xns95FDB36 28FD57cpub@127. 0.0.1...
      [color=blue]
      > How are you measuring this fact?[/color]

      By looking at Task Manager.
      [color=blue]
      > Dispose does not actually free the memory,[/color]

      According to the MSDN docs, the Dispose method "releases all resources used
      by the System.Componen tModel.Componen t" - are you saying that doesn't
      include the memory that the component has been allocated?


      Comment

      • Chad Z. Hower aka Kudzu

        #4
        Re: DataSet object not releasing memory

        "Mark Rae" <mark@mark-N-O-S-P-A-M-rae.co.uk> wrote in
        news:evkShBvEFH A.3032@TK2MSFTN GP12.phx.gbl:[color=blue][color=green]
        >> How are you measuring this fact?[/color]
        >
        > By looking at Task Manager.[/color]

        Never use TM for memory measurement, ESPECIALLY with .NET applications.
        [color=blue][color=green]
        >> Dispose does not actually free the memory,[/color]
        >
        > According to the MSDN docs, the Dispose method "releases all resources
        > used by the System.Componen tModel.Componen t" - are you saying that
        > doesn't include the memory that the component has been allocated?[/color]

        Correct. You should read up on the GC in .NET. In .NET release <> Free up
        memory.


        --
        Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
        "Programmin g is an art form that fights back"

        Empower ASP.NET with IntraWeb

        Comment

        • Cor Ligthert

          #5
          Re: DataSet object not releasing memory

          Mark,

          There should not be any reason to dispose a dataset, it cost only (very few)
          time.

          When you want to clear it, have a look at
          dataset.clear or dataset.reset

          Forcing the Garbage Collector will cost time at moments that it is
          inefficient.

          I hope this helps?

          Cor


          Comment

          • Mark Rae

            #6
            Re: DataSet object not releasing memory

            "Cor Ligthert" <notmyfirstname @planet.nl> wrote in message
            news:%23GoZM7zE FHA.560@TK2MSFT NGP15.phx.gbl.. .

            Cor,

            Thanks for the reply - some practical advice!
            [color=blue]
            > There should not be any reason to dispose a dataset, it cost only (very
            > few) time.
            >
            > When you want to clear it, have a look at
            > dataset.clear or dataset.reset[/color]

            OK - I'll certainly have a look at that.
            [color=blue]
            > Forcing the Garbage Collector will cost time at moments that it is
            > inefficient.[/color]

            Yes - I don't like to force a System.GC.Colle ct()...

            Mark


            Comment

            Working...