-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtest_gc.cpp
45 lines (34 loc) · 893 Bytes
/
test_gc.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "gc.h"
#include <iostream>
struct Test
{
Test() { std::cerr << "Test::Test\n"; }
~Test() { std::cerr << "Test::~Test\n"; }
void Do() { std::cerr << "Test::Do\n"; }
GARBAGE_COLLECT(Test);
};
typedef ELFE::GCPtr<Test> Test_p;
struct Derived : Test
{
Derived(Test *g, Test *u): glop(g), glap(u) { std::cerr << "Derived::Derived\n"; }
~Derived() { std::cerr << "Derived::~Derived\n"; }
Test_p glop;
Test_p glap;
GARBAGE_COLLECT(Derived);
};
typedef ELFE::GCPtr<Derived> Derived_p;
int main()
{
Test_p ptr = new Test;
Derived_p ptr2 = new Derived(ptr, ptr);
ptr2->Do();
new Derived(0, 0);
for (uint i = 0; i < 2030; i++)
{
new Test();
if (i > 2000)
ELFE::GarbageCollector::Collect();
}
ELFE::GarbageCollector::Collect(true);
ELFE::GarbageCollector::Collect(true);
}