任务管理器显示内存泄漏,但堆快照不显示(Task manager shows memory leak, but Heap snapshot doesn't)
我每5秒运行一次繁重的JavaScript,任务管理器显示内存使用量不断增加。 但是Heap快照没有。 如果我停止脚本,大约
半分钟后两分钟就会清除内存。更新:
如果我长时间离开脚本,内存会增加,直到浏览器崩溃。 我还尝试运行chrome dev工具的时间线测试,它们也没有显示内存使用量的增加,与Heap快照相同。 所以我想这是一种泄漏,但我无法理解什么是泄漏。
另一件我无法确认的事情,因为我无法安装以前的Chrome版本,因为我不记得之前发生过这种情况(<24个Chrome版本)。 IE10在不增加内存的情况下运行此测试。 这可能是新Chrome的问题吗?
I run heavy JavaScript every 5 seconds and task manager shows constant increase of memory usage. However Heap snapshot doesn't. If I stop the script, memory is cleared after about
half a minutetwo minutes.UPDATE:
If I leave the script for a long time, the memory increases until the browser crashes. I also tried to run timeline test of chrome dev tools, and they also don't show the increase of memory usage, same as Heap snapshot. So I guess it's some kind of a leak, but I can't understand what is leaking.
Another thing which I can't confirm, as I can't install previous Chrome versions is that I don't remember this happening on previous (<24 Chrome versions). And IE10 runs this test without increasing memory. Could this be issue of new Chrome?
原文:https://stackoverflow.com/questions/14467112
最满意答案
在PhantomJS中无法确定这一点。 关于
phantom.onError
的文档说:这是在PhantomJS中拥有全局错误处理程序的最接近的
这并没有捕捉到语法错误。 如果您尝试使用
--debug=true
选项运行它,您将看到许多调试消息,但最终错误仍然具有相同的信息量。我尝试的另一件事是使用第二个PhantomJS脚本,它读取原始脚本并尝试
eval
它。 在这种情况下触发phantom.onError
事件,但trace
参数为空。好处是PhantomJS / CasperJS脚本只是JavaScript,因此您可以将它们粘贴到http://jslint.com/或在它们上运行专用的jslinter以查看问题所在。 您必须在网站上标记一些选项,否则您将收到很多错误:
- 将
phantom
添加到全局变量框中,- 启用node.js模式和
- 容忍“一切”(或那些你真正想要容忍的东西)
It's not possible to determine this in PhantomJS itself. The documentation on
phantom.onError
says:This is the closest it gets to having a global error handler in PhantomJS
And this doesn't catch the syntax error. If you try to run it with the
--debug=true
option, you will see a lot of debug messages, but the final error has still the same amount of information.Another thing that I tried was to use a second PhantomJS script which reads the original script and tries to
eval
it. Thephantom.onError
event is triggered in this case, but thetrace
argument is empty.The good thing is that PhantomJS/CasperJS scripts are just JavaScript, so you can paste them to http://jslint.com/ or run a dedicated jslinter on them to see where the problem lies. There are some options that you have to mark on the site or otherwise you will get a lot of errors:
- add
phantom
to the global variables box,- enable node.js mode and
- tolerate "everything" (or those things that you actually want to tolerate)
相关问答
更多-
目前没有比1.1-beta3更新的版本包含此检查。 最简单的解决方法是打开bin / bootstrap.js文件并删除这些行或替换当前在主分支中的行 : (function (version) { // required version check if (version.major === 1) { if (version.minor < 8) { return __die('CasperJS needs at least PhantomJS v1 ...
-
使用节点运行文件。 如果有一个解析错误,它会报告。 如果文件有效,那么节点也将尝试运行它,如果您的脚本依赖于您节点环境中不可用的东西,则会失败。 所以你必须忽略任何运行时错误。 例如,给定hello-world.js: // Say Hello World twice for (var i=0; i<2; i++) { console.log("Hello World") ); } 运行它与节点 : node hello-world.js 输出: /home/someone/somewhere/he ...
-
CasperJS和PhantomJS触发“站点离线”浏览器没有(CasperJS and PhantomJS trigger “site is offline” browser doesn't)[2022-03-12]
我怀疑该网站知道你正在根据你的用户代理进行抓取,因为你多次点击它 也许尝试随意使用你的用户,看看会发生什么。 ( 见这里的清单 ) var casper = require('casper').create({ pageSettings: { userAgent: "USE SOME OTHER USER AGENT HERE" } }); 但是,在多个同时请求之后,该站点也可能被IP地址阻止。 因此,也尝试a)减慢脚本速度或b)导航到不同的页面 编辑 我把一个测试脚本拼凑起来,一切都适合 ... -
这是PhantomJS中的一个错误: http : //code.google.com/p/phantomjs/issues/detail? id = 930&start = 300 解决方法是暂时关闭GZIP压缩(或从Phantom发送虚假接受标头以欺骗服务器不发送压缩内容)。 This is a bug in PhantomJS: http://code.google.com/p/phantomjs/issues/detail?id=930&start=300 The workaround is to ...
-
只是一个注释,如果有人登陆这个问题 - 我在package.json和node-modules目录中有一个本地安装的npm'网页'模块我得到了同样的错误。 清除这些允许casperjs找到全局安装的幻像网页模块并为我修复此问题。 The problem turned out to be that I had a Phantom script called webpage.js in the directory from which I was trying to execute my Casper scri ...
-
在PhantomJS中无法确定这一点。 关于phantom.onError的文档说: 这是在PhantomJS中拥有全局错误处理程序的最接近的 这并没有捕捉到语法错误。 如果您尝试使用--debug=true选项运行它,您将看到许多调试消息,但最终错误仍然具有相同的信息量。 我尝试的另一件事是使用第二个PhantomJS脚本,它读取原始脚本并尝试eval它。 在这种情况下触发phantom.onError事件,但trace参数为空。 好处是PhantomJS / CasperJS脚本只是JavaScript ...
-
你有没有尝试过任何waitFor函数。 你可以尝试这样的事情: casper.test.begin('Main page test', 2, function suite(test) { casper.start('http://xxx.yyy.zzz/', function() { test.assertTitle('My page name', 'page title is set correctly'); }); casper.waitFor(functio ...
-
这只是因为网站http://compare.nissanusa.com/nissan_compare/NNAComparator/TrimSelect.jsp上存在javascript错误。 Parse Error不是因为您的代码。 Phantomjs在加载页面时并不喜欢js错误,这就是为什么添加错误处理程序很重要的原因。 要轻松捕获网页中发生的错误,无论是语法错误还是其他抛出的异常,请使用page.onError 。 这是一个基本的例子: page.onError = function(msg, trac ...
-
我自己找到了答案。 似乎phantomjs和casperjs支持命令行参数http://phantomjs.org/api/system/property/args.html 我的脚本现在看起来像这样。 test.php的 $user_input = $_POST['user_input']; putenv("PHANTOMJS_EXECUTABLE=/usr/local/bin/phantomjs"); exec('/usr/local/bin/casperjs hello.js $user_input ...
-
您应该使用Webpack作为预处理器: https : //github.com/webpack/karma-webpack 我个人使用这个,因为它更快: https : //github.com/aaronjensen/karma-webpack 您可能需要在您的业力配置中添加一些polyfills: files: [ './node_modules/babel-polyfill/dist/polyfill.js', './node_modules/phantomjs-polyfill/bind- ...