libjit
[Top][All Lists]
Advanced

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

Re: [Libjit] What is the purpose of incref?


From: Alexey Galakhov
Subject: Re: [Libjit] What is the purpose of incref?
Date: Tue, 19 Feb 2019 09:45:41 +0100

On Mon, 18 Feb 2019 23:58:29 -0600
Peng Yu <address@hidden> wrote:

> Hi,
> 
> I see incref appears many times in the manual. What is the purpose?

Hi,

it's about memory management and ownership. If the reference counter
reaches zero, the corresponding object is destroyed. Setting incref to
0 means that you care for object lifetime manually (and this will be
obligatory), while setting to 1 means that you pass the ownership to
the library and don't care. The correct choice depends on the way you
want to manage memory and destroy unused in your program.

If you set it to 0 in a program where it should be 1, you'll get a
crash or undefined behavior due to an use of deleted object.

If you set it to 1 in a program where it should be 0, you'll get a
memory leak.

Regards,

Alexey



reply via email to

[Prev in Thread] Current Thread [Next in Thread]