web.py 内存泄漏
我做错了什么或者 web.py 泄漏内存吗?
import web
class Index:
def GET(self): return 'hello web.py'
app = web.application(('/*', 'Index'), globals())
app.run()
运行上面的文件。观察任务使用了多少内存。在浏览器中转到 localhost:8080。关闭浏览器(以防止页面被缓存),然后再次打开页面,看看内存使用量如何上升。每次关闭浏览器并重新访问该页面时,它都会上升。
在 Win XP 上运行 python 2.6。
Am I doing something wrong or does web.py leak memory?
import web
class Index:
def GET(self): return 'hello web.py'
app = web.application(('/*', 'Index'), globals())
app.run()
Run the above file. Watch how much memory the task uses. Go to localhost:8080 in your browser. Close the browser (to keep the page from getting cached), then open the page again, and see how the memory usage rises. It goes up every time you close the browser and re-visit the page.
Running python 2.6 on Win XP.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
运行代码并向其发送数千个请求(通过另一个使用 urllib2 的 Python 进程)后,我发现它在前几百个请求的过程中增长了约 200k,然后停止增长。这看起来并不是不合理,而且也不一定表明存在内存泄漏。请记住,Python 通过引用计数和垃圾收集的组合来使用自动内存管理,因此不能保证它使用的每一块内存在不再使用时都可以重用;它可能会向操作系统请求内存,然后即使不再需要它也不会返回它。
所以我认为答案是:你没有做错任何事情,但是 web.py 不会泄漏内存。
After running your code and sending it thousands of requests (via another Python process using urllib2), I find that it grows by about 200k over the course of the first few hundred requests and then stops growing. That doesn't seem unreasonable, and it needn't indicate a memory leak. Remember that Python uses automatic memory management via a combination of reference counting and garbage collection, so there's no guarantee that every bit of memory it uses is reusable the instant it's no longer in use; and it may request memory from the OS and then not return it even though it isn't needed any more.
So I think the answer is: You aren't doing anything wrong, but web.py doesn't leak memory.