On Thu, Jan 01, 2004 at 09:10:28PM +0100, Marcus Holland-Moritz wrote:
| On 2004-01-01, at 19:09:51 +0000, [EMAIL PROTECTED] wrote:
|
| > |
| > | You can simply add a CLEANUP section (see 'perldoc perlxs' and search
| > | for CLEANUP) to your wlgetbyid() XSUB and free the memory allocated
| > | by g_strdup():
| > |
| > | CLEANUP:
| > | free(str); /* or similar call to free the memory */
| > |
| > | This should take care of your memory leakage.
| >
| > Hmms.. maybe I've found some other problem.
| > I have a function where a AV* array is created and returned.
| > Who should delete/free this array?
|
| Code?
Here it goes :)
AV*
dicgetvals(id, word)
int id
U32 word
INIT:
AV* array;
CODE:
if (id > MAXDICS || id < 0 || !dics[id]) {
array = NULL;
} else {
int i;
guint32 wid;
float val;
array = newAV();
for (i=0;i<MAXENTRY;i++) {
wid = dictionary_get_id(dics[id],word,i);
val = dictionary_get_val(dics[id],word,i);
if (val == 0.0) break;
av_push(array, newSVuv(wid));
av_push(array, newSVnv(val));
}
}
RETVAL = array;
OUTPUT:
RETVAL
|
| Normally you shouldn't have to care and perl should take care
| of freeing the AV. What you have to take care of is Reference
| Counts. 'perldoc perlguts' has a section on it.
I think I am managing reference counts correctly. All references (calls
to this function) use my vars, which should be freed every time it goes
out of scope.
Thanks.
Alb
|
| --
| IBM:
| It may be slow, but it's hard to use.
--
Departamento de Informatica - Universidade do Minho
"The C Programming Language -- A language which combines the
flexibility of assembly language with the power of assembly language."