Hi,

On Fri, Aug 19, 2016 at 7:56 AM, Ken Takata <ktakata65...@gmail.com> wrote:
> Hi Yegappan,
>
> 2016/8/19 Fri 23:08:16 UTC+9 yega...@gmail.com wrote:
>> Hi all,
>>
>> On Thu, Aug 18, 2016 at 5:47 AM, Yegappan Lakshmanan
>> <yegapp...@gmail.com> wrote:
>> > Hi all,
>> >
>> > The attached patch adds support for setting and getting a context to/from
>> > a quickfix/location list. There is a refcount problem with this diff 
>> > (which I am
>> > not able to solve).
>> >
>> > If the context is a number or a string, then the patch works without any
>> > issues. If the context is a List or a Dict, then Vim crashes if garbage
>> > collection runs. For example, the following works:
>> >
>> >     :call setqflist([], 'a', {'context':[1,2,3]})
>> >     :echo getqflist({'context':1})
>> >
>> > But the following doesn't work:
>> >
>> >     :call setqflist([], 'a', {'context':[1,2,3]})
>> >     :call garbagecollect()
>> >     :echo getqflist({'context':1})
>> >
>> > Any suggestions on how to copy the context with proper update to the
>> > reference count so that garbage collection doesn't free the List/Dict?
>>
>> Any suggestions on how to fix the reference count issue?
>
> I struggled with reference counting and garbage collection when I implemented
> lambda and closure.
>
> Vim uses mark-and-sweep garbage collection. If an object is not marked, it
> will be collected even if the refcount is not zero. This is needed because
> reference counting cannot handle circular reference. To mark an object, you
> need to update the copyID member in the object (dict or list).
> Please check the garbage_collect() function in eval.c and also
> set_ref_in_XXX() functions.
>

Thanks for the suggestion. This seems to work. I have added a
set_ref_in_quickfixlist() function to mark the quickfix context
objects.

But this seems inefficient. Every time garbage collection runs,
the context of the location list for all the windows (across all
the tabs) needs to be marked. If there are too many tabs/windows,
this may take some time.

Also, how do I verify that the context is eventually garbage collected
when it is no longer referenced? I can run Vim under valgrind and look
for memory leaks. But is there a simpler way?

Regards,
Yegappan

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui