当前位置:网站首页>Memory leak caused by C UserControl
Memory leak caused by C UserControl
2022-04-22 01:33:00 【Kingston】
Test Engineering csdn Download address :https://download.csdn.net/download/wojiuguowei/85195072
Concept
out of memory : The common understanding is that there is not enough memory , There is unrecoverable memory in the system or the memory used for program operation is greater than the maximum memory available , As a result “Out of memory” Or something like that , Make the program not work properly .
Memory leak : Memory leak refers to the situation that the program cannot release or timely release the memory that is no longer used due to negligence or error , After the application allocates a certain section of memory , Because of a design mistake , Lost control of this segment of memory , As a result, the memory cannot be recycled and cannot be recycled in time , Finally, problems that may cause the program to run slowly or crash .
Possible causes of memory leaks :
1、 Your object is still referenced but not actually used . Because they are quoted , therefore GC They will not be collected , In this way, they will be permanently saved and occupy memory .
2、 When you allocate unmanaged memory in some way ( There is no recycling ) And don't release them .
Derived classes inherit from UserControl, This control class contains picture、button Other controls
The example I tested , It is reflection that generates objects of this type , Use the default function Dispose Free memory , The test code is as follows
while(true)
{
string tmp = string.Format("WindowsFormsApp10.UserControl1");
Type type = Type.GetType(/*"LocalPLC.Base.PlcType"*/ tmp);
if (type == null)
{
return;
}
//object obj = type.Assembly.CreateInstance(type);
UserControl1 user1 = (UserControl)Activator.CreateInstance(type) as UserControl1;
user1.Dispose();
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
}
Above code , I thought I would recycle memory , But memory growth
Just started memory

Run for a period of time, memory

Memory does not increase , It has also dropped a lot , explain dipose You can delete the child controls in the control , If you are not at ease , You can add a... In the derived class clear function , Then traverse the child controls , Each child control is then dispose
public void Clear()
{
foreach (Control control in this.Controls)
{
{
control.Dispose();
}
}
}
Reference link :
https://blog.csdn.net/qq_43360872/article/details/110846779
https://stackoverflow.com/questions/44371471/c-sharp-usercontrols-memory-leak
https://www.coder.work/article/6324862
版权声明
本文为[Kingston]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220126369251.html
边栏推荐
- Appium mobile terminal automated testing -- building a simulator and real machine environment
- Emotional control of investment
- 一个朋友的方法
- Code source daily question div1 (101-109)
- mysql 查询 上个月20号到 当前系统月份(本月)19号之间的数据
- Codeforces Round #783 (Div. 2)
- 天边的彩虹很美丽
- Compiled vs interpreted, dynamic vs static
- Network protocol analysis summary
- PR carries out JPEG frame compression and exports it as AVI video
猜你喜欢

Tencent Android development interview experience, HR's words pierced my heart

The sandbox and design egg have reached a cooperation to jointly establish a virtual space Como small world

Node靶机渗透测试

为什么PR导出来的视频,偏紫色?

【Pranet】论文及代码解读(Res2Net部分)——peiheng jia

多屏幕模式下idea窗口找不到

Blazor University (12)组件 — 组件生命周期

Test d'automatisation de l'extrémité mobile appium - - mise en place d'un simulateur et d'un environnement réel

The middle order traversal of binary tree

【ing】MATLAB工具包-Dynamic Copula Toolbox 3.0详解
随机推荐
PHY6222国产低功耗多协议蓝牙SoC芯片
Blazor University (12)组件 — 组件生命周期
Nexus数据迁移
A friend's way
PR进行jpeg的帧压缩,并导出为avi视频
MATLAB实现多元正态Copula分布
trollcave靶机渗透测试
(9) The edit of jvcl is combined with opening file, opening directory, selecting time, button, calculator and IP address
cybox靶机渗透测试
【ing】MATLAB工具包-Dynamic Copula Toolbox 3.0详解
Emotional control of investment
投资对情绪的把控
MySQL crée un utilisateur de connexion à distance et autorise
谷粒商城-学习笔记-基础篇-商品服务1(P45-P58)
理论,智慧,学习
网络模型 LSTM模型内容详解
QT campus barter system
Matlab: simulate the control system and use ode45 to solve the LC circuit
php.ini Module ‘redis‘ already loaded in Unknown on line 0
天边的彩虹很美丽