Re: [gdome]Re: reference counting again



> Again. Let's see the critical iteration!

OK. you've convinced me now that there's a problem somewhere. Possibly in
the importNode method that I've never seen used before. In the meantime,
let's try the following code which is more natural (to me) and, by the
way, doesn't crash:

  newnode = gdome_n_cloneNode(node, TRUE, &exc);
  root = (GdomeNode*) gdome_doc_documentElement(self, &exc);

  while ((tmpnode = gdome_n_firstChild(newnode, &exc)) != NULL) {
    GdomeNode* n1 = gdome_n_removeChild(newnode, tmpnode, &exc);
    GdomeNode* n2 = gdome_n_appendChild(root, n1, &exc);
    gdome_n_unref(tmpnode, &exc);
    gdome_n_unref(n1, &exc);
    gdome_n_unref(n2, &exc);
  }

(note that I use cloneNode instead of importNode)

Another remark:

> Gdome_n_appendChild() also increases the reference 
> count of tmpnode (and so the no. of live nodes). So that I should 
> dereference tmpnode two times, if I don't want my program leak memory. 

you are right, but that's because appendChild _does_return_ the appended 
node. So it's better (even though more verbose) to create another temp 
variable and to unref that variable instead, as I've done in the example 
above. It's much more clear and doesn't rely on Gdome2 side effects.
Unfortunately, when using C + reference counting, you cannot just forget 
about useless returned values ;-(

I hope Paolo will be able to have a look at your example in the next days.

luca





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]