locked
Any way to Reduce Memory Usage on VB.Net Application RRS feed

  • 問題

  • Hi

    I am implementing a VB.Application, in which I need to use a lot of DataTable, ArrayList ...etc. To process the data. E.g. Every 5 mins

    Could you give me some suggestion about how to reduce the system memory usage?

    Will Datatable = nothing release the used memory from data table?

    Thanks in Advance
    2008年5月16日 下午 03:24

解答

  • sorry guys...

     

    I don't know there has no "null" in vb, my fault.

     

    ChiYau:

    Here is a simple sample:

    Code Snippet

    Dim al As ArrayList
    al = New ArrayList();

    'Call Clear before set nothing

    al.Clear()
    al = Nothing

     

    Dim dt As DataTable
    dt = New DataTable()

    'Call Dispose before set nothing
    dt.Dispose()
    dt = Nothing

     

     

    Make sure there has no reference:

    Code Snippet

    Dim al As ArrayList
    al = New ArrayList()
    al.Add("a")
    al.Add("b")
    al.Add("c")
    al.Add("d")
    al.Add("e")
    al.Add("f")

    Dim s As String
    s = CType(al(0), String)
    s = Nothing
    'Set the reference to nothing before call Clear
    al.Clear()
    'Call Clear before set nothing
    al = Nothing

     

     

    Enjoy~
    2008年5月19日 上午 09:52

所有回覆

  • Hello, ChiYau.
    You may set the reference-typed variable to be null or Nothing.
    The memory will then be reclaimed by the Garbage Collector.

    Regards,
    Allen Mak
    2008年5月17日 下午 02:56
  • First, make sure you didn't reference anymore to the DataTable, ArrayList, and call Dispose to those objects.

    remember to set object to null before set to nothing

     

    2008年5月18日 上午 09:39
  • Hi Allen & Jacky

    Thanks for your information,

    After I set the variable to Nothing, Shall I call Dispose method as well?

    To Jacky: What do you mean by "make sure you didn't reference anymore to the DataTable, ArrayList"?
    You mean do not pass that Datatable object into another method?

    In VB.Net I i cannot use tbl=null, do you mean to user tbl.clear()?

    Many thanks

    2008年5月19日 上午 07:25
  •  ChiYau 寫信:
    Hi Allen & Jacky
    In VB.Net I i cannot use tbl=null, do you mean to user tbl.clear()?

     

    Hi Chi,

     

    null is only available in C#, you may set your object to Nothing in VB.NET

     

    Regards,

    Colt

    2008年5月19日 上午 09:24
  • sorry guys...

     

    I don't know there has no "null" in vb, my fault.

     

    ChiYau:

    Here is a simple sample:

    Code Snippet

    Dim al As ArrayList
    al = New ArrayList();

    'Call Clear before set nothing

    al.Clear()
    al = Nothing

     

    Dim dt As DataTable
    dt = New DataTable()

    'Call Dispose before set nothing
    dt.Dispose()
    dt = Nothing

     

     

    Make sure there has no reference:

    Code Snippet

    Dim al As ArrayList
    al = New ArrayList()
    al.Add("a")
    al.Add("b")
    al.Add("c")
    al.Add("d")
    al.Add("e")
    al.Add("f")

    Dim s As String
    s = CType(al(0), String)
    s = Nothing
    'Set the reference to nothing before call Clear
    al.Clear()
    'Call Clear before set nothing
    al = Nothing

     

     

    Enjoy~
    2008年5月19日 上午 09:52
  • Hi Colt & Jacky

    Thanks for your information. I understood now.

    Thanks a lot.
    2008年5月19日 上午 10:08
  • Hi Allen

     

    On 8 Oct, after first day of TechEd, we are going to host a community gathering where you can have a drink and network with your peers in the industry, please RSVP with me at hkdevcom@microsoft.com.

     

    Event Details

    Date: 8 Oct, 2008 (Wednesday)

    Time: 7pm to 9pm

    Venue: Cenna Bar & Lounge (銅鑼灣軒尼詩道525號恒和鑽石大廈23)

     

    Thanks and looking forward to seeing you at the event!

     

    Cheers,

    Angela Ip (MSHK)

     

    2008年9月25日 上午 08:26