peerigon / phridge

A bridge between node and PhantomJS
The Unlicense
519 stars 50 forks source link

phantom.dispose() causes 'cannot call function of deleted QObject' when page was already closed #43

Closed frank-weindel closed 8 years ago

frank-weindel commented 8 years ago

In my application I'm calling page.close() within phantom manually when I'm done with a page. When I'm done with the phantom instance I call phridge's phantom.dispose() but I get the following error when I do this after the call to page.close().

cannot call function of deleted QObject
  at reject (node_modules/phridge/lib/phantom/start.js:71:69)
  at run (node_modules/phridge/lib/phantom/start.js:109:15)
  at run (node_modules/phridge/lib/phantom/start.js:160:12)
  at loop (node_modules/phridge/lib/phantom/start.js:30:12)
    -----------------------------------------------------------------------
    at Phantom._send (node_modules/phridge/lib/Phantom.js:165:20)
    at Phantom.run (node_modules/phridge/lib/Phantom.js:95:17)
    at dispose (node_modules/phridge/lib/Phantom.js:147:14)
    at init (node_modules/when/lib/makePromise.js:39:5)
    at new Promise (node_modules/when/lib/makePromise.js:27:53)
    at Function.promise (node_modules/when/when.js:97:10)
    at Phantom.dispose (node_modules/phridge/lib/Phantom.js:139:17)
    at Generator._killPhantom (modules/generator/index.js:307:23)
    at Generator.stop (modules/generator/index.js:303:15)
    at Object.poolModule.Pool.destroy (endpoints/generate.js:28:15)

If I remove the call to page.close() this does not happen. I'm calling it because the phantom instance is reused many times and I want to clear out any resources being used before creating a new page using phridge's phantom.createPage().

Seems like phridge has no way to tell if a page it has created has been closed from within phantom. So when phantom.dispose is called its trying to close pages which are already closed.

jhnns commented 8 years ago

Since phridge is holding a reference to the page object itself, you should not call page.close() for yourself without notifying phridge. The page object provided by phridge has a dispose() method. Just call this, and phridge will internally call page.close() and remove all references.

jhnns commented 8 years ago

Did this resolve your problem?