the garbage collector has a problem to dispose the objects in below code (in VIP build 802). Please have a look.
To begin with I take a working code version which creates a number of objects, calls garbageCollect/0, and in doing so it outputs the number of alive objects.
Code: Select all
interface someObj
end interface someObj
%---
class someObj : someObj
properties
count : unsigned (o).
end class someObj
%---
implement someObj
class facts
count : unsigned := 0.
facts
objReference : someObj [used].
clauses
new() :-
objReference := This,
count := count + 1.
clauses
finalize() :-
count := count - 1.
end implement someObj
%===
implement main
constants
count = 1000.
clauses
run() :-
stdIO::write("<1>\n", someObj::count, " objects exist\n"),
foreach _ = std::cIterate(count) do
_ = someObj::new()
end foreach,
stdIO::write(count, " objects created\n"),
stdIO::write("<2>\n", someObj::count, " objects exist\n"),
stdIO::write("garbageCollect()", '\n'),
memory::garbageCollect(),
stdIO::write("<3>\n", someObj::count, " objects exist\n").
end implement main
Code: Select all
<1>
0 objects exist
1000 objects created
<2>
1000 objects exist
garbageCollect()
<3>
1 objects exist
Now I change the domain of the objReference fact:
Code: Select all
interface someObj
end interface someObj
%---
class someObj : someObj
properties
count : unsigned (o).
end class someObj
%---
implement someObj
class facts
count : unsigned := 0.
domains %%% new %%%
objReference = objReference(someObj). %%% new %%%
facts
objReference : objReference [used]. %%% changed %%%
clauses
new() :-
objReference := objReference(This), %%% changed %%%
count := count + 1.
clauses
finalize() :-
count := count - 1.
end implement someObj
%===
implement main
constants
count = 1000.
clauses
run() :-
stdIO::write("<1>\n", someObj::count, " objects exist\n"),
foreach _ = std::cIterate(count) do
_ = someObj::new()
end foreach,
stdIO::write(count, " objects created\n"),
stdIO::write("<2>\n", someObj::count, " objects exist\n"),
stdIO::write("garbageCollect()", '\n'),
memory::garbageCollect(),
stdIO::write("<3>\n", someObj::count, " objects exist\n").
end implement main
Code: Select all
<1>
0 objects exist
1000 objects created
<2>
1000 objects exist
garbageCollect()
<3>
1000 objects exist