Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Release Memory allocation for Datagridview

Posted on 2009-05-20
5
308 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Store results in vb.net 3 24
Sql server insert 13 36
VB.NET 2008 - SQL Timeout 9 34
Create a datatable in vb.net dynamically 1 22
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 …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

839 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