|
From: Dmitry F. <dim...@gm...> - 2013-01-16 13:27:35
|
Hello.
This story has continuation.
As I already said, I use hybrid approach: I use DOM to modify the tree, and
use VTD for navigation. That works extremely faster than execute XPath
directly in DOM (about 5 times faster)
Of course, when tree is changed, I need to generate XML and reparse it via
VTD. And, of course, all bookmarks becomes invalid. That's OK, and I
controlled this myself: i stored some integer number (say, vtd_number),
and, when reparsing, this vtd_number is increased. Each object that
represents node has VTD's context, and a vtd_number for which this context
is valid.
Everything worked fine until I started using BookMark instead of my own
int[] context implementation.
The problem is that each BookMark has a reference to VTDNav instance. Every
time document is changed, new VTDNav is created, and new one should be
collected by GC, but, since I have many objects with BookMarks, they aren't.
Today I have spent several hours until I found memory leak. Currently I
switched back to my own int[] implementation, but, maybe you have some
suggestion how to solve it better?
Thanks.
2013/1/15 Dmitry Frank <dim...@gm...>
> Thanks, that is what I need.
>
> Unfortunately I missed this.
>
>
> 2013/1/15 <jz...@xi...>
>
> check out bookMark, which may be what u are looking for...
>>
>>
>>
>> ----- Original Message -----
>> From:
>> Dmitry Frank <dim...@gm...>
>>
>> To:
>> <vtd...@li...>
>> Cc:
>>
>> Sent:
>> Mon, 14 Jan 2013 19:39:29 +0400
>> Subject:
>> [Vtd-xml-users] Randomly save and restore VTDNav's context
>>
>>
>> Hello.
>>
>> For my app, it's very convinient to save current context of VTDNav and
>> restore it whenever I want
>>
>> But there's only two ways to save/restore context I know from the docs:
>> push()/pop(), and NodeRecorder.
>>
>> Neither of these ways are convinient for me: I need for really random
>> access. Not stack way, like push()/pop(), and no NodeRecorder way. that
>> can only iterate saved items node-by-node.
>>
>> I need to be able to get context as a byte array, and to restore it in
>> the same manner.
>>
>> So, I added the following methods to the VTDNav.java :
>>
>> /** * Return context that can be restored later by calling
>> restoreContext(). * by dfrank. */ public int[] getContext() { int[] ret =
>> new int[ stackTemp.length ]; for (int i = 0; i < nestingLevel; i++) { ret
>> [i] = context[i]; } ret[nestingLevel] = l1index; ret[nestingLevel + 1] =l2index
>> ; ret[nestingLevel + 2] = l3index; ret[nestingLevel + 3] = l2lower; ret[nestingLevel
>> + 4] = l2upper; ret[nestingLevel + 5] = l3lower; ret[nestingLevel + 6] =l3upper
>> ; if (atTerminal) ret[nestingLevel + 7] =1; else ret[nestingLevel + 7] =0
>> ; ret[nestingLevel+8] = LN; return ret; } /** * Restore context that
>> was returned by getContext(). * by dfrank. */ public booleanrestoreContext
>> (int[] saved_context) { for (int i = 0; i < nestingLevel; i++) { context[
>> i] = saved_context[i]; } l1index = saved_context[nestingLevel]; l2index =saved_context
>> [nestingLevel + 1]; l3index = saved_context[nestingLevel + 2]; l2lower =saved_context
>> [nestingLevel + 3]; l2upper = saved_context[nestingLevel + 4]; l3lower =saved_context
>> [nestingLevel + 5]; l3upper = saved_context[nestingLevel + 6];atTerminal
>> = (saved_context[nestingLevel + 7] == 1); LN = saved_context[nestingLevel
>> +8]; return true; }
>>
>> These methods work nicely, and they help me a lot to do what I need.
>>
>> So, questions:
>> Why there's no similar methods in the release of VTD-XML? Do them break
>> anything, or whatever?
>>
>>
>> --
>> Dmitry
>>
>>
>
|