Improve some wording in reference counting documentation (#1523)
JerryScript-DCO-1.0-Signed-off-by: Geoff Gustafson geoff@linux.intel.com
This commit is contained in:
committed by
Zoltan Herczeg
parent
bd488e6efb
commit
6e5b759319
@@ -11,7 +11,7 @@ by `jerry_release_value`.
|
|||||||
/* The value stored in the 'global' variable contains a live
|
/* The value stored in the 'global' variable contains a live
|
||||||
* reference to the global object. The system also keeps its
|
* reference to the global object. The system also keeps its
|
||||||
* own live reference to the global object. These two references
|
* own live reference to the global object. These two references
|
||||||
* are indepent, and both must be destroyed before the global
|
* are independent, and both must be destroyed before the global
|
||||||
* object can be freed. */
|
* object can be freed. */
|
||||||
|
|
||||||
jerry_release_value (global);
|
jerry_release_value (global);
|
||||||
@@ -48,16 +48,17 @@ following code is an **INCORRECT WAY** of releasing the 3.14 value.
|
|||||||
|
|
||||||
JerryScript API functions returning with a `jerry_value_t` always
|
JerryScript API functions returning with a `jerry_value_t` always
|
||||||
return with a new live reference. Passing a `jerry_value_t` to
|
return with a new live reference. Passing a `jerry_value_t` to
|
||||||
an API function never releases its reference. The next example
|
an API function never releases its reference (unless explicitly
|
||||||
shows this behaviour through property getting and setting.
|
stated in the documentation). The next example shows this
|
||||||
|
behaviour through property getting and setting.
|
||||||
|
|
||||||
```c
|
```c
|
||||||
jerry_value_t prop_value = jerry_get_property (...);
|
jerry_value_t prop_value = jerry_get_property (...);
|
||||||
|
|
||||||
/* The prop_value must be released later because both the base
|
/* The prop_value must be released later because both the base
|
||||||
* object and the prop_value have an independent reference to
|
* object and the prop_value have an independent reference to
|
||||||
* the same JavaScript value. When the operation is failed
|
* the same JavaScript value. When the operation fails, the
|
||||||
* the prop_value contains a live reference to an error object.
|
* prop_value contains a live reference to an error object.
|
||||||
* This reference must be released as well. */
|
* This reference must be released as well. */
|
||||||
|
|
||||||
if (jerry_value_has_error_flag (prop_value))
|
if (jerry_value_has_error_flag (prop_value))
|
||||||
@@ -76,20 +77,21 @@ shows this behaviour through property getting and setting.
|
|||||||
|
|
||||||
/* Property setting is the same. */
|
/* Property setting is the same. */
|
||||||
|
|
||||||
|
jerry_value_t new_prop_value = jerry_create_number (2.718);
|
||||||
jerry_value_t result = jerry_set_property (..., new_prop_value);
|
jerry_value_t result = jerry_set_property (..., new_prop_value);
|
||||||
|
|
||||||
/* If the property set is successful a new reference is created
|
/* If the property set is successful, a new reference is created
|
||||||
* for the value referenced by new_prop_value. The new_prop_value
|
* for the value referenced by new_prop_value. The new_prop_value
|
||||||
* reference must be released regardless the operation is
|
* reference must be released regardless of whether the operation
|
||||||
* successful. */
|
* is successful. */
|
||||||
|
|
||||||
/* The new_prop_value can be passed to other JerryScript API
|
/* The new_prop_value can be passed to other JerryScript API
|
||||||
* functions before the jerry_release_value () call. */
|
* functions before the jerry_release_value () call. */
|
||||||
|
|
||||||
jerry_release_value (new_prop_value);
|
jerry_release_value (new_prop_value);
|
||||||
|
|
||||||
/* The reference stored in 'result' variable contains whether
|
/* The reference stored in the 'result' variable is live whether
|
||||||
* the operation is successful and must also be freed. */
|
* the operation is successful or not, and must also be freed. */
|
||||||
|
|
||||||
if (jerry_value_has_error_flag (result))
|
if (jerry_value_has_error_flag (result))
|
||||||
{
|
{
|
||||||
@@ -170,5 +172,5 @@ References can be duplicated in C as long as only one of them is freed.
|
|||||||
jerry_release_value (c);
|
jerry_release_value (c);
|
||||||
/* Both 'b' and 'c' (boolean true) references become dead. */
|
/* Both 'b' and 'c' (boolean true) references become dead. */
|
||||||
|
|
||||||
/* Since all references are released no memory leak is possible. */
|
/* Since all references are released, no memory leak occurs. */
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user