In a C# project I'm working on for an iterative design application, I need
to dispose of a large arrray of a struct object and reinitialize the
array between iterations.
That is, the user starts a design, and the program creates an array of
objects defined as follows:
public struct DES_TYPE
{
public string short_string;
public string long_string;
public int entryNo;
public int col;
public int row;
};
The class contains an array of the struct above and two variables that
specify the size of the array:
public class PrincipalClass
{
// create reference to array
public DES_TYPE [,] desType;
// array size
int noCols, noRows;
// class constructor
public PrincipalClass ( int no_cols, int no_rows)
{
// initialize variables
noCols = no_cols;
noRows = no_rows;
// allocate array
desType = new DES_TYPE [ noCols, noRows];
// code to initialize array elements
} // end class
Each time the user starts a new design, the array should be initialized.
It is not known beforehand what its size will be, although a typical
size is on the order of a million objects. I need some
way of freeing the memory. I can't quite see a way of
implementing the IDisposable interface here. The
mechanics of the creating the Dispose ( ) method
aren't in question. What I can't see is how to
dispose of the elements in the struct, that is,
the two strings and three integers *and reclaiming the
memory.*
Anybody see a way around this? For one thing, I don't
mind creating a single instance of the PrincipalClass
when the program is started, and then intializing the array
for each design iteration. But I need a way to free up the
memory used by the array before starting a new design iteration.
What am I overlooking?