Re: Question about proper garbage collection

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hi Willy,

thanks for your immediate response. That's kind of true. But it doesn't
explain to me why I get this System.OutOfMemoryException sometimes!?

Above code sample was not complete. Maybe the error occurs in here
(short sample):

....
ArrayList* myList = new ArrayList();

for(int i=0; i < 1000; i++)
{
tempFolder = new Folder();
tempFolder->id = new Byte __gc[80]; // allocate 80 bytes
tempFolder->name = "tempName";

for(int j=0; j < 80; j++) // fill this array now
tempFolder->id[j] = xxx;

// now, sometimes I have to allocate more than the 80 bytes above.
// so I do this:
if(condition)
{
tempFolder->id = new Byte __gc[200]; // allocate even more
memory
// fill array again and work with it
}
myList->Add(tempFolder);
}

So I just allocate another buffer without caring about the already
allocated 80 bytes.
The question is, if the 80 bytes allocated before are LOST or if they
are freed during the next garbage collection cycle?


Thanks again in advance,

TheLetti

.



Relevant Pages

  • despair
    ... $ ALLOCATE 'tape_drive' ... $ INIT 'tape_drive' 'label' ... I have lost what little faith in humanity remained in me. ...
    (comp.os.vms)
  • allocation problem
    ... I'm rewriting a program I made before because I lost the ... source and I want to allocate a number of text strings that are 500 ...
    (comp.lang.cpp)