Question regrading NPObject onwership when calling NPN_InvokeDefault()
I have written an NPAPI
plug-in to interact with JavaScript
. My JavaScrip开发者_如何学JAVAt
code loads this plug-in and makes an Async call on it supplying a callback. When the callback (JS) needs to be invoked from my plug-in
, I'm calling NPN_InvokeDefault()
. The parameters I want to pass to the JavaScript
include: An NPObject
that I have created and converted that to NPVariant
before passing to NPN_InvokeDefault().
My question is who takes the ownership of this object - Am I responsible for freeing this Object by calling NPN_ReleaseVariantValue()
? Or is this owned by Webkit
(in JS context)?
You'll probably want to look at my blog post on the subject: http://npapi.com/memory
The short answer is that anything that you retain control of after a call you should release. Since with InvokeDefault you still have control of your NPVariant array afterwords you need to release all of the NPVariants; if the code on the other side of InvokeDefault needs to hold on to it it is responsible for retaining, copying, etc as needed.
The only exception to this rule is that when you return a NPVariant from a function on your NPObject you lose control of it and the browser is responsible for releasing it; similarly anything that the browser returns to you from InvokeDefault (the return value) it is your responsibility to release.
Hope that helps.
精彩评论