垃圾收集器是否删除其父线程的子线程占用的内存 [英] Does garbage collector remove memory occupied by child threads of its parent thread

查看:91
本文介绍了垃圾收集器是否删除其父线程的子线程占用的内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Windows服务,用VB.Net编码。



服务包含主要的父线程,它在三个间隔后休眠分钟。



当父线程开始执行时,它会创建多个子线程,其任务是处理查询并将数据转储到 MYSQL 相关表格中。



我的问题是子线程是在父级内部创建的线程,那么垃圾收集器以三分钟的间隔清除子线程所占用的内存,或者我们需要手动将脚本写入清除< Thread的数据。



因为我得到了 System.OutOf.Memory.Exception ,它停止了服务的执行。< br $> b $ b

我尝试过的事情:



任何人都可以帮我解决这个问题。

解决方案

参见垃圾收集基础| Microsoft Docs [ ^ ]:

Quote:

每个托管进程都有一个托管堆。进程中的所有线程都为同一堆上的对象分配内存。

因此垃圾收集会影响进程所有线程的内存。



如果内存不足,我建议减少/优化内存使用量。


I have Windows service which is coded in VB.Net.

Service contains the main parent Thread which sleeps after interval of three minutes.

When parent Thread start the execution it create multiple Child Threads whose task is to process the query and dump the data into MYSQL related tables.

My question is that the Child Thread are created inside parent Thread,so what Garbage Collector cleans the memory occupied by the Child Thread's at an interval of three minutes or we need to manually write the script to clear the <Thread's data.

Because i get the System.OutOf.Memory.Exception which stops the execution of the service.

What I have tried:

Can any one help me to resolve this issue.

解决方案

See Fundamentals of Garbage Collection | Microsoft Docs[^]:

Quote:

There is a managed heap for each managed process. All threads in the process allocate memory for objects on the same heap.

So the garbage collection affects the memory from all threads of a process.

If you run out of memory I suggest to reduce / optimise memory usage.


这篇关于垃圾收集器是否删除其父线程的子线程占用的内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆