Marcus Holland-Moritz
2006-03-23 19:58:13 UTC
Hi
array = newAV();
av_push(array, newSVuv(dictionary_get_occ(D, wid)));
for (j = 0; j < MAXENTRY; j++) {
twid = 0;
prob = 0.0;
twid = dictionary_get_id(D, wid, j);
if (twid) {
prob = dictionary_get_val(D, wid, j);
tword = word_list_get_by_id(T, twid);
av_push(array, newSVpv(tword, strlen(tword)));
av_push(array, newSVnv(prob));
}
}
RETVAL = newRV_noinc((SV*)array);
The question is: the objects created here (newSVpv, newSVnv and the
array) are freed in case they are no more used?
Yes. :-)array = newAV();
av_push(array, newSVuv(dictionary_get_occ(D, wid)));
for (j = 0; j < MAXENTRY; j++) {
twid = 0;
prob = 0.0;
twid = dictionary_get_id(D, wid, j);
if (twid) {
prob = dictionary_get_val(D, wid, j);
tword = word_list_get_by_id(T, twid);
av_push(array, newSVpv(tword, strlen(tword)));
av_push(array, newSVnv(prob));
}
}
RETVAL = newRV_noinc((SV*)array);
The question is: the objects created here (newSVpv, newSVnv and the
array) are freed in case they are no more used?
When in doubt, it's usually a good idea to check the reference counts
with Devel::Peek:
use Devel::Peek;
$a = some_xsub_call();
Dump $a;
For example:
***@r2d2 ~ $ perl -MConvert::Binary::C -MDevel::Peek -e'$a = Convert::Binary::C->new->parse("typedef int a[];")->unpack("a", "x"x12); Dump $a'
SV = RV(0x819ada0) at 0x8148fb4
REFCNT = 1
FLAGS = (ROK)
RV = 0x8148e1c
SV = PVAV(0x814dedc) at 0x8148e1c
REFCNT = 1
FLAGS = ()
IV = 0
NV = 0
ARRAY = 0x81612e8
FILL = 2
MAX = 3
ARYLEN = 0x0
FLAGS = (REAL)
Elt No. 0
SV = IV(0x815e80c) at 0x8148fd8
REFCNT = 1
FLAGS = (IOK,pIOK)
IV = 2021161080
Elt No. 1
SV = IV(0x815e810) at 0x8163e40
REFCNT = 1
FLAGS = (IOK,pIOK)
IV = 2021161080
Elt No. 2
SV = IV(0x815e814) at 0x8163df8
REFCNT = 1
FLAGS = (IOK,pIOK)
IV = 2021161080
If all refcounts are 1, the objects will be freed as soon as the last
reference to them ($a) vanishes.
Marcus
--
This file will self-destruct in five minutes.
This file will self-destruct in five minutes.