Python 的内存泄露,内存直接爆炸

2017-02-09 17:32:19 +08:00
 qsnow6
````
import time
b_time = bytes(int(time.time()))
print(b_time)
````

ubuntu 16.04 64bit下,一运行,内存直接爆炸
8307 次点击
所在节点    Python
53 条回复
lostsquirrelX
2017-02-10 14:35:50 +08:00
应该是死在 print 上面
Felldeadbird
2017-02-10 14:56:32 +08:00
有意思!弄成恶作剧发给同事、
hezhile
2017-02-10 15:06:25 +08:00
Python 3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:27:37) [MSC v.1900 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import time
>>> b_time = bytes(int(time.time()))
>>> print(b_time)
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
print(b_time)
File "C:\Users\gilot\AppData\Local\Programs\Python\Python35\lib\idlelib\PyShell.py", line 1343, in write
return self.shell.write(s, self.tags)
OverflowError: cannot serialize a string larger than 4GiB
>>>

在 process explorer 里面, pythonw.exe 的 private bytes 确实飙升到了 7.3G (我的电脑内存只有 8G )
操作系统是 win10 pro ,有大概 10 秒钟的时间整个系统没有反应
wuruxu
2017-02-10 15:23:00 +08:00
怎么爆炸了,一点反应也没有
```
xyz@debian:~$ python
Python 2.7.9 (default, Jun 29 2016, 13:08:31)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> b_time = bytes(int(time.time()))
>>> print(b_time)
1486711277
>>> ls
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'ls' is not defined
>>>
xyz@debian:~$

```
kkk330
2017-02-10 15:50:36 +08:00
就像 38 楼说的,我也记得 Linux 下内存或者硬盘空间都可以申请超过实际大小(并不会真的分配给你,感觉炸了说不通啊
langjiyuan
2017-02-10 20:49:51 +08:00
已 get 可以忽悠 有些自大的舍友去调试了
zhjits
2017-02-11 14:03:12 +08:00
http://imgur.com/a/r14mh
这个内存泄漏可能是真的……
zhjits
2017-02-11 14:05:01 +08:00

目前内存占用似乎到顶了, print 执行过程中一直保持这个值
zhjits
2017-02-11 14:10:34 +08:00

print 完内存占用就回去了,没泄露,只是 print 的 format 过程占用内存稍微大了一点而已
q397064399
2017-02-11 21:45:56 +08:00
内存泄露是指程序申请的堆内存没有被正常回收导致内存泄露
Khlieb
2017-02-12 08:50:35 +08:00
熊叔: boom
cxbats
2017-02-12 11:32:10 +08:00
这也叫泄漏?那 malloc(1000000000) 是不是也叫内存泄漏
ericbize
2017-02-16 23:02:09 +08:00
@freestyle 不是日常使用,只是偶尔开开,那个输入中文的话还好

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/339348

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX