recursion lead to out of memory
There are two storage areas involved: the stack and the heap. The stack is where the current state of a method call is kept (ie local variables and references), and the heap is where objects are stored. The Hotspot documentation says that on Linux 64-bit each thread has a stack of 1024kB by default. The heap can be made arbitrary big, and today it's in the order of GB.
A recursive method uses both the stack and the heap. Which one you run out of first depends on the implementation. As an example, consider a method which needs thousands of integers: if they are declared as local variables, ie:
publicvoid stackOverflow(){int a_1;int a_2;int a_3;// ...int a_10_000_000;}
your program will crask with a StackOverflowError
. On the other hand, if you organize your integers in an array, like:
publicvoid outOfMemory(){int[] integers =newint[10*1000*1000];}
the heap will be filled soon, and the program will end with an OutOfMemoryError
. In neither case the memory is corrupted or data overridden.
Solution:
need to switch to a disk based structure, a database or a memory mapped hashtable.
recursion lead to out of memory的更多相关文章
- Allowing GPU memory growth
By default, TensorFlow maps nearly all of the GPU memory of all GPUs (subject to CUDA_VISIBLE_DEVICE ...
- SAP NOTE 1999997 - FAQ: SAP HANA Memory
Symptom You have questions related to the SAP HANA memory. You experience a high memory utilization ...
- detect data races The cost of race detection varies by program, but for a typical program, memory usage may increase by 5-10x and execution time by 2-20x.
小结: 1. conflicting access 2.性能危害 优化 The cost of race detection varies by program, but for a typical ...
- Java性能提示(全)
http://www.onjava.com/pub/a/onjava/2001/05/30/optimization.htmlComparing the performance of LinkedLi ...
- 2.5 – Garbage Collection 自动垃圾回收 Stop-the-world vs. incremental vs. concurrent 垃圾回收策略
2.5 – Garbage Collection 自动垃圾回收 Lua 5.3 Reference Manual http://www.lua.org/manual/5.3/manual.html# ...
- debugging tools
https://blogs.msdn.microsoft.com/debugdiag/ https://blogs.msdn.microsoft.com/debuggingtoolbox/2012/1 ...
- 计算机体系结构-内存调优IPC OOMK
man ipc [root@server1 proc]# man ipcIPC(2) Linux Programmer’s Manual ...
- Linux kernel Programming - Concurrency and Race Conditions
Concurrency and Its Management Race condition can often lead to system crashes, memory leak,corrupte ...
- 02 Go 1.2 Release Notes
Go 1.2 Release Notes Introduction to Go 1.2 Changes to the language Use of nil Three-index slices Ch ...
随机推荐
- 使用zookeeper实现分布式master选举(c 接口版本)
zookeeper,已经被很多人所熟知,主要应用场景有(数据订阅/发布 ,负载均衡, 命名服务, 分布式协调/通知,集群管理,Master选举,分布式锁,分布式队列). C接口的描述 主要参考 Ha ...
- Azure + vsftpd + ubntu14 + 虚拟用户 遇到的问题:从网上摘抄
:在Azure安装好ubuntu虚拟机,安装包选择ubuntu14.04 LTS,选择LTS,以便微软对其以后的更好支持,不选就可能技术支持不会很久,现只开一台,端口默认选择22 :打开虚拟机,进入端 ...
- JS对select动态添加options操作[IE&FireFox兼容]
<select id="ddlResourceType" onchange="getvalue(this)"> </select> 动态 ...
- android-support-xxxx.jar NoClassDefFoundError
当你的项目出现以下红色提示的时候,要小心了,因为很可能因为这个错误而导致解释不通的异常出现. Found 2 versions of android-support-v4.jar in the dep ...
- Spring MVC与easyui国际化
1.建立资源文件 在webapp下建立文件夹language,在其中再添加file,命名分别为language.properties,language_en.properties,language_z ...
- vim 安装与运行以及代码的运行
vi功能是最弱的,也是*nix操蛋之后最基本的editor.后来vi被增强加入众多特性,这就是vim.再后来vim加入图形接口,gvim诞生了.功能最强的是gvim,它的很多特性vim并不支持,vi更 ...
- JavaScript移除数组元素减少长度的方法
JavaScript移除数组元素减少长度的方法,代码如下: //数组移除长度方法 var array=[]; array[0]="张三"; array[1]="李四& ...
- 判断php数组维度的小例子
分享一例判断php数组维度的代码,供大家参考. 如下所示: <?php /** * 返回数组的维度 * @param [type] $arr [description] * @return [t ...
- C# new的用法
在 C# 中,new 关键字可用作运算符.修饰符或约束. 1)new 运算符:用于创建对象和调用构造函数.这种大家都比较熟悉,没什么好说的了. 2)new 修饰符:在用作修饰符时,new 关键字可以显 ...
- postgresql 开启远程访问
1.如果服务器启用了防火墙,需要在防火墙上开启 5432 端口. 2.修改 PostgreSQL 配置文件 postgresql.conf.postgresql.conf,Linux 配置文件所在路径 ...