Boehm GC $B%i%$%V%i%j$r;H$C$F(B C/C++ $B$G$b%,%Y!<%8%3%l%/%7%g%s$7$h$&(B

$B:[email protected]|!'(B2002.10.9
$B=$@5F|!'(B2004.01.8


Boehm GC $B%i%$%V%i%j$H$O(B

$B$3$3$G!"(B Boehm GC$B$H8F$V$N$O(B H. Boehm$B!"(BA. Demers$B!"(BM. Weiser $B$N(B 3 $B?M$K$h$C$F(B $B=q$+$l$?J]
Java $B$NEP>l$K$h$C$F(B GC $B$b?M8}$Kg:_U$7$F$-$^$7$?!#(B $B$7$+$7!"B?$/$N?M$,$^$@(B $B@lMQ$N%W%m%0%i%`8@8l$H%$%s%?%W%j%?(B $B%i%s%?%$%`$,(B $B$J$1$l$P(B GC $B$O;H$($J$$$H9M$($F$$$^$9!#(B Boehm GC $B%i%$%V%i%j$O!"(B $B=>Mh$N(B C $B8@8l$N(B malloc $B4X?t$r(B GC_malloc $B4X?t$XCV$-49$((B free $B4X?t$r $BEvA3!"(B C++ $B8@8l$K$bBP1~$7$F$$$^$9!#(B $B$^$?!"$"$J$?$N:n$C$?(B $B%$%s%?%W%j%?=hM}7O$K(B Boehm GC $B%i%$%V%i%j$rAH$_9~$a$P!"(B $B<+F0E*$K(B GC $B$,MxMQ2DG=$K$J$j$^$9!#(B

Boehm GC $B$O!"(B $B$[$H$s$I$N(B UNIX $B7O(B OS$B!"(BWin9x $B7O!"(BNT$B7O!"(BOS/2$B!"(BAmiga OS$B!"(B Mac OS 8$B!&(B9$B$KBP1~$7$F$$$^$9!#(B
($B$?$@$7!"(BOS / CPU $B$K$h$C$F5!G=@)8B$r
Boehm GC $B$N%Z!<%8(B "A garbage collector for C and C++"$B$O!"(B $B8=:_(B $B$3$3(B $B$K$"$j$^$9!#(B

$B%,!<%Y!<%8%3%l%/%7%g%s(B

GC $B$K$D$$$F(B $B$b$&(B1$BEY$*$5$i$$$r$7$^$9!#(B
C/C++ $B$G$O(B malloc ($B$^$?$O(B new)$B$K$h$C$FF0E*$K3NJ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!#(B
void foo(char** p) {
  char c;
  *p = &c;
}

char* p = NULL;
foo(&p);
/* p $B$OIT@5$J%a%b%j%"%I%l%9$r;X$7$F$$$k(B */
$B%@%s%0%j%s%0%]%$%s%?$NCf$G(B $B:G$bH/8+$,8+$D$1?I$$$N$,!"(B $BK\Mh(B $B@5>o$J%*%V%8%'%/%H$r;X$7$F$$$?%]%$%s%?$,!"(B $B;2>H$7$F$$$k%*%V%8%'%/%H$,2rJ|$5$l$?$?$a$K(B $B%@%s%0%j%s%0%]%$%s%?$r;X$7$F$7$^$&%Q%?!<%s$G$9!#(B
char* p = (char*) malloc(SIZE);
free(p);

char* q = (char*) malloc(SIZE);

/* p $B$OIT@5$J%a%b%j%"%I%l%9$r;X$7$F$$$k(B */
/* $B$b$7$+$9$k$H(B p == q $B$G!"(Bp $B$r=q$-D>$9$H(B q $B$NFbMF$,JQ$o$k$+$b(B */
$B2rJ|$5$l$?NN0h$,!"(B $Bl9g!"(B $BIT@5$J=q$-JQ$($r9T$C$F$7$^$$$^$9!#(B
$B$3$N$h$&$K(B $B%a%b%j$N2rJ|$K$O4m81$,$D$-$^$H$$$^$9!#(B $B$=$3$G(B free $B$d(B delete $B$N$h$&$K%W%m%0%i%`$,L@<(E*$K2rJ|$r;X<($9$k$N$G$O$J$/!"(B $B%W%m%0%i%`<+BN$,(B$BITMW(B$B$K$J$C$?%*%V%8%'%/%H$rH=CG$7$F!"(B $B<+F0E*$K2s<}$r9T$&5!9=$,(B$B%,!<%Y!<%8%3%l%/%7%g%s(B$B$G$9!#(B

$B%$%s%9%H!<%k(B

$B$^$:!"(B $B%=!<%9%3!<%I$,I,MW$G$9!#(B $B$3$3$+$i(B $B%=!<%9%3!<%I$r;}$C$F$-$^$7$g$&!#(B $B8=:_$N:G?7%P!<%8%g%s$O(B 6.1$B!"%U%!%$%kL>$O(B gc6.1.tar.gz $B$G$9!#(B $B$3$3$G$O!"(B UNIX $B7O(B OS $B$G$N%$%s%9%H!<%kJ}K!$K$D$$$F@bL@$7$^$9!#(B
> tar xzvf gc6.1.tar.gz
> cd gc6.1/ > ./configure > make > make check > su # make install
$B%i%$%V%i%j$r;H$&$?$a$KI,MW$J(B include $B%U%!%$%k$O%$%s%9%H!<%k$5$l$F$$$^$;$s!#(B gc6.1/include $B$N2<$N%U%!%$%k$r!"E,Ev$J%G%#%l%/%H%j$K%3%T!<$7$F$*$-$^$7$g$&!#(B
# cp -r  include /usr/local/include/gc
LD_LIBRARY_PATH $B$K%i%$%V%i%j$r%$%s%9%H!<%k@h$N%G%#%l%/%H%j$rF~$l$^$9!#(B (Linux $B$J$i(B ld.so.conf $B$K%$%s%9%H!<%k@h$N%G%#%l%/%H%j$rDI2C$7$F!"(B ldconfig $B%3%^%s%I$r
$B99?7MzNr!'(B
2004.01.08 dangling pointer $B$NNc$,4V0c$C$F$$$k$H$N;XE&$r$$$?$@$$$?$N$G=$@5!#(B

$BLa$k(B
Written by NAKAMURA Minoru, Email: nminoru atmark nminoru dot jp, Twitter:@nminoru_jp