Best properly way to destroy a 2 dimensional array?

Jonathan Villa via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Apr 6 13:12:49 PDT 2016


On Wednesday, 6 April 2016 at 19:54:32 UTC, Jonathan Villa wrote:
> I wrote a little program that given some number it generates a 
> list of different combinations (represented by a ubyte array), 
> so in the end my function with name GenerateCombinations(int x) 
> returns a ubyte[][] (list of arrays of ubytes).
>

Sample code.

void main()
{
	while(true)
	{
		write("Alternatives quantity: ");
		string value = chomp(readln());
		
		if (value == "x")
			break;
		
		int x = to!int(value);
		
		ubyte[][] combs = GenerateCombinations(x);
		writefln("There are %d combinations.", combs.length);
		
		foreach(ubyte[] a; combs)
			destroy(a);
		destroy(combs);
		
		writeln();
		
		GC.collect();
		GC.minimize();
	}
	
	return;
}




More information about the Digitalmars-d-learn mailing list