Re: Garbage collection, part two...

From: Felix Lee <flee_at_teleport.com>
Date: Thu, 06 Apr 2000 18:27:17 -0700

Shiro Kawai <shiro_at_squareusa.com>:
> > STk_makestring(CHARS(STk_makestring("one")));
>
> STk_makestring creates its own copy, so shouldn't it be OK?

no, that code is equivalent to:
    tmp1 = STk_makestring("one");
    tmp2 = CHARS(tmp1);
    result = STk_makestring(tmp2);

an optimizing compiler is allowed to notice that tmp1 isn't
used any more and reuse it like so:
    tmp1 = STk_makestring("one");
    tmp1 = CHARS(tmp1);
    result = STk_makestring(tmp1);

and in this version, at line 3 there are no more references
to the SCM object created at line 1. So it may become
garbage collected when line 3 tries to allocate space for a
new object. So the second call to STk_makestring can end
up doing an invalid access to a dead object.
--
Received on Fri Apr 07 2000 - 03:27:46 CEST

This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 19:38:59 CEST