From 6e5b75931936a4f17dfa11ea614c889898c634f2 Mon Sep 17 00:00:00 2001 From: Geoff Gustafson Date: Mon, 16 Jan 2017 00:59:30 -0800 Subject: [PATCH] Improve some wording in reference counting documentation (#1523) JerryScript-DCO-1.0-Signed-off-by: Geoff Gustafson geoff@linux.intel.com --- docs/06.REFERENCE-COUNTING.md | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/docs/06.REFERENCE-COUNTING.md b/docs/06.REFERENCE-COUNTING.md index 720c7f23d..5758adc0e 100644 --- a/docs/06.REFERENCE-COUNTING.md +++ b/docs/06.REFERENCE-COUNTING.md @@ -11,7 +11,7 @@ by `jerry_release_value`. /* The value stored in the 'global' variable contains a live * reference to the global object. The system also keeps its * 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. */ 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 return with a new live reference. Passing a `jerry_value_t` to -an API function never releases its reference. The next example -shows this behaviour through property getting and setting. +an API function never releases its reference (unless explicitly +stated in the documentation). The next example shows this +behaviour through property getting and setting. ```c jerry_value_t prop_value = jerry_get_property (...); /* The prop_value must be released later because both the base * object and the prop_value have an independent reference to - * the same JavaScript value. When the operation is failed - * the prop_value contains a live reference to an error object. + * the same JavaScript value. When the operation fails, the + * prop_value contains a live reference to an error object. * This reference must be released as well. */ 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. */ + jerry_value_t new_prop_value = jerry_create_number (2.718); 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 - * reference must be released regardless the operation is - * successful. */ + * reference must be released regardless of whether the operation + * is successful. */ /* The new_prop_value can be passed to other JerryScript API * functions before the jerry_release_value () call. */ jerry_release_value (new_prop_value); - /* The reference stored in 'result' variable contains whether - * the operation is successful and must also be freed. */ + /* The reference stored in the 'result' variable is live whether + * the operation is successful or not, and must also be freed. */ 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); /* 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. */ ```