Click here to Skip to main content
15,071,928 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good Day

This may be a stupid question but...
If you have a public datatable used for info between programs visual studio
Public Shared DtRptDisc As New DataTable("DtRptDisc")

If the case scenario is that you want to refresh the datatable and you do as follows
DtRptDisc = New Datatable

Is this creating a duplicate instance ? or recreating the same instance?
Meaning that the previous Datable is still resident in memory as was not disposed?
So meaning is this cycle repetitively done will this chew up resources? Does not seem to but unsure.

What I have tried:

Google Search, Have not disposed of the datatable in the App as currently or continuously in use so a global resource been used all the time.
Posted
Updated 21hrs ago

1 solution

If you want to make sure the DataTable is disposed, you can use a using clause in C# like this:
using (DataTable table = new DataTable())
{
  // your code
}

For the VB.NET syntax see: Using Statement - Visual Basic | Microsoft Docs[^]
   
v2
Comments
Grid-Code 7hrs 15mins ago
   
Hi RickZeeland

Appreciate the c# Snip
So New Datatable disposes the Prior one - Brilliant

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900