当前位置:网站首页>How to write code that is not easy to overflow memory
How to write code that is not easy to overflow memory
2022-06-10 13:12:00 【An immortal pleasant goat】
Why did it run out of memory ?
as a result of : constantly new object ( Strong reference objects are not JVM The recycling , Even if the memory overflows, it will not be recycled )
How to write code that is not easy to overflow memory ?
void functionA(){
// To use less new Object to create a strongly referenced object
for(){
// Here you can create soft reference objects , If there is a memory overflow , Soft reference objects are also recycled
functionB();
}
}
void functionB(){
//functionB It is best to create weak reference objects in , such , When the scope is JVM When it's recycled , Weakly referenced objects are also recycled
}
summary
1、for Loop call method , The object of the method is preferably a weakly referenced object (new weakreference)
2、 The object of the main method body , If possible , Is to use soft reference objects (new softreference)
边栏推荐
- GNN is used as the new backbone of the three major tasks of CV, with the same cost performance as CNN, Vit and MLP | Chinese Academy of Sciences & Huawei Noah open source
- Six stone programming: talking about naming based on the position of word processing
- [raise bar C #] how to call the base of the interface
- Can qiniu open an account? Is it safe to open an account in qiniu
- 不吐不快
- Leetcode 96. 不同的二叉搜索樹
- Unity3d uses URP rendering pipeline to realize ar shadow (shadow casting and transparent ground)
- 【FAQ】运动健康服务REST API接口使用过程中常见问题和解决方法总结
- 日本版arXiv凉得一批:2个多月了,才收到37篇论文
- Neuron Newsletter 2022-05|新增 2 个南向驱动和 1 个北向应用、Modbus TCP 实现定制扩展
猜你喜欢

SAP Field Service Management 和微信集成的案例分享和实现介绍

Leetcode 96. Different binary search trees

【Spark】(task8)SparkML中的pipeline通道建立

用C语言创建基本的栈与队列

手机厂商“返祖”,只有苹果说不

QT database application 22 file coding format recognition

Shi Yigong and other teams posted on the cover of Science: AI and freeze electron microscope revealed the structure of "atomic level" NPC, a breakthrough in life science

Qt数据库应用22-文件编码格式识别

Wechat web development tool tutorial, the company develops Web

Automatic mapping of tailored landmark representations for automated driving and map learning
随机推荐
统计100以内的各位数之和为7的自然数的个数及平均值
MySQL master database operation large table DDL, slave database crash and system parameter error setting
How can the team be dissolved...
KITTI 相关信息汇总
SAP Field Service Management 和微信集成的案例分享和实现介绍
Alibaba cloud ECS server builds MySQL database
【抬杠C#】如何实现接口的base调用
今天,一对情侣拿下香港最大电商IPO
【Spark】(task8)SparkML中的pipeline通道建立
Handling work ticket system
六石编程学:以文字处理的位置,谈谈命名
Site investigation system
Use unique to quickly remove duplicate elements
The Japanese version of arXiv is a cool batch: only 37 papers have been received after more than 2 months
UML class diagram
Vdo-slam source code reading notes [2] local optimization and global optimization
Software project management 6.10 Cost budget
Tidb elementary course experience 8 (cluster management and maintenance, adding a tikv node)
eKuiper Newsletter 2022-05|protobuf 编解码支持、可视化拖拽编写规则
list. Remove (index) returns false, removal failed