<div dir="ltr">Hi,<div><br></div><div>My question in short: is it necessary to call JSValueProtect right after object/value creation in C++? I don&#39;t know the semantics of the GC, but I&#39;m assuming that almost any call to a JSC function that takes a context may run a garbage collection cycle. Therefore, if I&#39;m not immediately returning the created object, it might get cleaned up prematurely.</div>

<div><br></div><div>Could you share some advice on the proper usage of JSValueProtect and on keeping objects from going away unexpectedly?</div><div><br></div><div>Some background info:</div><div><br></div><div>I&#39;m experiencing intermittent bugs in my C++ to JS binding, I&#39;m only guessing that GC might be related to that. What I&#39;m seeing is that objects created in C++ are occasionally missing their properties.</div>

<div><br></div><div>In one example, there is a single code path from C++ to JS that takes a native object and creates a corresponding JS object using appropriate JSClassRef (which is prepopulated with some methods).</div>

<div><br></div><div>In the JS land, there is always the same method called on the object (the one that has just been created in C++ land with the appropriate JSClassRef). 9 out of 10 times it works fine, but every once in a while I get an exception &quot;undefined is not a function&quot;, i.e. the method on the object is missing.</div>

<div><br></div><div>The way I&#39;m linking native and JS objects is by keeping an associative array of their pointers, so that I can get back to the native object in the C++ callback called from JS.<br></div><div><div><br>

</div>-- <br>Best regards<br>Alexei Sholik
</div></div>