Solved

Release Memory allocation for Datagridview

Posted on 2009-05-20
5
299 Views
Last Modified: 2012-05-07
Hi,

I have a datagridview populated with data. I would like to be able to clear the dataand release the memory alocated for that data with a reset switch. The data in the grid isnt bound when I create the grid I create the columns and the data.

Using VB.NET 2005

Michal
0
Comment
Question by:MichMat
  • 2
  • 2
5 Comments
 
LVL 15

Accepted Solution

by:
oobayly earned 250 total points
ID: 24429877
The garbage collector should clean up any unused objects. However you need to make sure that any references to the data are no longer used.
You can forcibly can call Collect on the Garbage Collector.
GC.Collect()

Open in new window

0
 
LVL 48

Assisted Solution

by:jpaulino
jpaulino earned 250 total points
ID: 24429885
If you want to clear the columns/rows you can use:

Me.DataGridView1.Rows.Clear()
Me.DataGridView1.Columns.Clear()

' If you have datasource
Me.DataGridView1.DataSource = Nothing
But you don't need to clean the memory because the CLR will do that for you using the Garbage Collector. If you want to force the GC to work you can use:

GC.Collect()
GC.WaitForPendingFinalizers()
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 24429890

So slow this morning ... I have to warm up better :)
0
 
LVL 15

Expert Comment

by:oobayly
ID: 24429919
I know the feeling :-) It's a more detailed answer though.
0
 

Author Closing Comment

by:MichMat
ID: 31583404
THank you both
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now