Search code examples
cefsharpchromium-embedded

Bound objects not releasing


I instantiated a ChromiumWebbrowser on a modal form and then bind an object via JavascriptObjectRepository.Register method. Upon closing the form and re-opening a new modal form and invoking a method on the bound object I notice the bound object's method is incrementally invoking. So after modal has been opened, closed then reopened the bound object's method will be invoked twice and on subsequent open / close cycles this count will increase.

How do I release a bound object from CEF.

I have tried to detect if the object is bound already (using IsBound) but it returns false, however it still executes the method incrementally as the form is opened / closed.

ChromiumWebBrowser brwsr = new ChromiumWebBrowser("");
if (brwsr.JavascriptObjectRepository.IsBound("test"))
                return;
brwsr.JavascriptObjectRepository.Register("test", [object]);

Solution

  • The issue experienced was due to the bound object having an event handler that was not released on close of the form containing the cef browser. On subsequent launches of the form the bound object would get the event handler assigned again and cause the issue experienced. This was not an issue with cef but rather the bound object I used.