Home - ScSofts/AutoGC GitHub Wiki
example:
#include "auto_gc.h"
using namespace AutoGC;
//define your own class
class ObjTest:
public Object{
public:
ObjTest(){}
virtual void Delete()override{delete this;}//override a pure-virtual method
}
void func_use_heap(){
Heap heap;
ObjTest &obj = heap.New<ObjTest>();//Using new 20000 times is OK,when function end,it will be collected.
}
int main(void){
//initialize garbage collector
GC_Init(20);
func_use_heap();
//shutodown the garbage collector
GC_Shut();
return 0;
}
4 Steps to use GC:
-
Initialize the GC
-
create a heap (shouldn't in main function)
-
call heap.New
-
shutdown the GC