T
the.newsletter
Hello,
I'm not quite sure if all objects in my code are released properly by
the garbage collector, because under some circumstances (I didn't
figure them out yet) I encounter sometimes a
System.OutOfMemoryException.
It would be nice if someone of you could tell me if all the memory is
freed correctly by the garbage collector in the following short sample.
All I want to do within this code is to build an ArrayList of self
defined objects (from class Folder) and return them.
Please consider this code:
---------- MyFolder.h ------------
public __gc class Folder
{
public:
Byte id __gc[];
String* name;
};
---------- end of MyFolder.h ------
--------- MyFolder.cpp ------------
// constructor:
Folder::Folder()
{
this->id = null;
this->name = "";
}
// somewhere within a test method:
ArrayList* testMethod()
{
ArrayList* myList = new ArrayList();
for(int i=0; i < 1000; i++)
{
tempFolder = new Folder();
tempFolder->id = new Byte __gc[80];
tempFolder->name = "tempName";
for(int j=0; j < 80; j++) // fill this array now
tempFolder->id[j] = xxx;
myList->Add(tempFolder);
}
return myList;
}
--------- end of MyFolder.cpp -------------------
My concrete question is now, if tempFolder is released properly, or if
I have to release it manually or set to null after each and every loop
cycle!?? Or would it be of any advantage to call GC->Collect() after
every loop cycle??
Thank you in advance
for your hints,
TheLetti
I'm not quite sure if all objects in my code are released properly by
the garbage collector, because under some circumstances (I didn't
figure them out yet) I encounter sometimes a
System.OutOfMemoryException.
It would be nice if someone of you could tell me if all the memory is
freed correctly by the garbage collector in the following short sample.
All I want to do within this code is to build an ArrayList of self
defined objects (from class Folder) and return them.
Please consider this code:
---------- MyFolder.h ------------
public __gc class Folder
{
public:
Byte id __gc[];
String* name;
};
---------- end of MyFolder.h ------
--------- MyFolder.cpp ------------
// constructor:
Folder::Folder()
{
this->id = null;
this->name = "";
}
// somewhere within a test method:
ArrayList* testMethod()
{
ArrayList* myList = new ArrayList();
for(int i=0; i < 1000; i++)
{
tempFolder = new Folder();
tempFolder->id = new Byte __gc[80];
tempFolder->name = "tempName";
for(int j=0; j < 80; j++) // fill this array now
tempFolder->id[j] = xxx;
myList->Add(tempFolder);
}
return myList;
}
--------- end of MyFolder.cpp -------------------
My concrete question is now, if tempFolder is released properly, or if
I have to release it manually or set to null after each and every loop
cycle!?? Or would it be of any advantage to call GC->Collect() after
every loop cycle??
Thank you in advance
for your hints,
TheLetti