内存释放查询 [英] Memory Freeing Inqury

查看:72
本文介绍了内存释放查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢 Daniel Newby 回答我的内存使用问题(以及Martin York的解释)还有一点).这绝对是我一直在寻找的答案,但是我的其他问题更多是由其他人回答的.

Additional thanks extend to Daniel Newby for answering my memory usage question (and Martin York for explaining it a bit more). It is definitely the answer I was looking for, but more of my other questions were answered by others.

清除我所有的疑虑.非常高兴看到事情按我期望的方式运行.

for clearing up all of my concerns. Very pleased to see things running how I expect them to run.

我遇到了我不确定的事情.

在我的程序中,我没有使用malloc()free().我正在使用new制作类的实例,并确保每个实例在delete d 时都在destructor上运行,但是,没有free()调用或甚至将其指针(指向全局范围内的事物或其他类)设置为NULL0.

In my program, I'm not using malloc()or free(). I'm making instances of my classes with new and I've made sure each one runs it's destructor when it's delete'd, however, there are no free() calls or even setting their pointers (to things inside a global scope, or other classes) to NULL or 0.

我确定"的意思不是说我称每个析构函数.我只使用delete来调用析构函数来运行,但是每次创建一个对象以及每次运行析构函数时,我的变量都会增加1.这就是我确保创建的对象数量等于调用的析构函数的数量的方式.

我还是应该使用malloc()free()吗?我应该NULL指向仍然想要存在的事物的指针吗?

Should I be using malloc() and free() anyway? Should I be NULLing pointers to things that I still want to exist?

第二个问题是,为什么当我看任务管理器时,我的进程从不丢掉"内存?它曾经永远不会停止增长,然后我正确地开始了deleting一切.还是我想.

A second question is why, when I look at my task manager, does my process never "drop" memory? It used to never stop gaining, and then I started deleting everything properly. Or so I thought.

free()delete不会降低内存使用率吗?

Wouldn't free() or delete make the memory usage go down?

对于带有链接列表的malloc'ing和free'ing记忆,我应该采取什么做法?

What practices should I pursue about malloc'ing and free'ing memory with linked lists?

推荐答案

在C ++程序中很少有理由使用malloc()free().坚持使用newdelete.请注意,与具有垃圾回收的语言不同,在C ++中将指针设置为NULL或0与释放内存无关.

There's rarely a reason to use malloc() and free() in a C++ program. Stick with new and delete. Note that unlike languages with garbage collection, setting a pointer to NULL or 0 in C++ has nothing to do with deallocating the memory.

这篇关于内存释放查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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