Redian新闻
>
Win32 TerminateProcess 会有memory leak吗?
avatar
Win32 TerminateProcess 会有memory leak吗?# Programming - 葵花宝典
z*e
1
照几个说法的话,Windows下面不管是用TerminateProcess()强行中止程序也好,还是
自然地return也好,process所使用的一切内存都会被release,那么这样子就不应该有
memory leak啊?
就算用ExitProcess(),也只是可能destructor不被调用,最终process所占用的空间仍
然会在结束后回收?
实在不清楚。
avatar
y*i
2
Process都终结了,没有memory leakage
memory作为process的一种资源, process结束时全都释放了

【在 z***e 的大作中提到】
: 照几个说法的话,Windows下面不管是用TerminateProcess()强行中止程序也好,还是
: 自然地return也好,process所使用的一切内存都会被release,那么这样子就不应该有
: memory leak啊?
: 就算用ExitProcess(),也只是可能destructor不被调用,最终process所占用的空间仍
: 然会在结束后回收?
: 实在不清楚。

avatar
z*e
3
那这样子说起来的话,windows下根本就不会有memory leak的问题啊?
例如我写一个:
int main()
{
char* buf=new char[1024];
}
然后运行,这个process结束后heap内存也有系统自动回收,就没有memory leak?

【在 y*****i 的大作中提到】
: Process都终结了,没有memory leakage
: memory作为process的一种资源, process结束时全都释放了

avatar
z*e
4
又google了一下。
实际上malloc/new是通过win32的HeapAllocate之类的分配heap内存,而这个heap内存
实际上是windows通过类似memory pool之类的东西实现的,总之process结束后整个
process heap全部一笔勾销,所以其实不用delete也不会有memory leak.
是么?
又有提到说如果load了DLL,那么如果TerminateProcess,DLL里面可能会有leak,Why
?因为DLL是另外一个process memory space?
avatar
t*t
5
你能不能说说现在哪个OS不是这样……

【在 z***e 的大作中提到】
: 那这样子说起来的话,windows下根本就不会有memory leak的问题啊?
: 例如我写一个:
: int main()
: {
: char* buf=new char[1024];
: }
: 然后运行,这个process结束后heap内存也有系统自动回收,就没有memory leak?

avatar
c*e
6
程序不会.DLL是另外一个进程,不free library, 计数不为零, 不会释放的.
avatar
z*e
7
right right, every OS has its memory pool or whatever for applicaiton to
allocate memory and then put it back.
If so, why do we have the experience that the windows becomes slow after
using it for a while. e.g. When you first start windows, the used memory is
around 400Mb, then you play WOW, use Visual Studio, open bunch of browsers,
and you terminate all the applications (using task manager). Supposingly the
memory usage should be back to the initial phase which is around 400Mb, but
in most cas

【在 t****t 的大作中提到】
: 你能不能说说现在哪个OS不是这样……
avatar
k*k
8
not only those programs run in the system bah..

is
,
the
but

【在 z***e 的大作中提到】
: right right, every OS has its memory pool or whatever for applicaiton to
: allocate memory and then put it back.
: If so, why do we have the experience that the windows becomes slow after
: using it for a while. e.g. When you first start windows, the used memory is
: around 400Mb, then you play WOW, use Visual Studio, open bunch of browsers,
: and you terminate all the applications (using task manager). Supposingly the
: memory usage should be back to the initial phase which is around 400Mb, but
: in most cas

avatar
t*t
9
那是早年间的事了吧,现在的windows没那么差
我在公司和家里的机器都是几个月不重启一次的
早年间windows对资源的管理有不少毛病,现在就算还有毛病也比较轻微了。
不过firefox和ie7都吃内存吃得厉害。firefox我几天就手动重启一次。ie7几天就自动
垮一次。

is
,
the
but

【在 z***e 的大作中提到】
: right right, every OS has its memory pool or whatever for applicaiton to
: allocate memory and then put it back.
: If so, why do we have the experience that the windows becomes slow after
: using it for a while. e.g. When you first start windows, the used memory is
: around 400Mb, then you play WOW, use Visual Studio, open bunch of browsers,
: and you terminate all the applications (using task manager). Supposingly the
: memory usage should be back to the initial phase which is around 400Mb, but
: in most cas

avatar
k*k
10

~~~~~~~~~ this may be a memory management strategy. :)
firefox, //sigh, I really really hate its idea of caching everything.

【在 t****t 的大作中提到】
: 那是早年间的事了吧,现在的windows没那么差
: 我在公司和家里的机器都是几个月不重启一次的
: 早年间windows对资源的管理有不少毛病,现在就算还有毛病也比较轻微了。
: 不过firefox和ie7都吃内存吃得厉害。firefox我几天就手动重启一次。ie7几天就自动
: 垮一次。
:
: is
: ,
: the
: but

avatar
m*t
11

is
,
the
but
The OS may have cached more files in the memory, or some of the services are
started. Just because it doesn't go back to around 400Mb, it doesn't mean
there are memory leaks.

【在 z***e 的大作中提到】
: right right, every OS has its memory pool or whatever for applicaiton to
: allocate memory and then put it back.
: If so, why do we have the experience that the windows becomes slow after
: using it for a while. e.g. When you first start windows, the used memory is
: around 400Mb, then you play WOW, use Visual Studio, open bunch of browsers,
: and you terminate all the applications (using task manager). Supposingly the
: memory usage should be back to the initial phase which is around 400Mb, but
: in most cas

avatar
y*i
12
you need to learn more about the operating system concepts, I guess
avatar
j*g
13
操作系统的资源不是只有内存而已
不然.Net里面不会有IDisposable这个接口存在
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。