- 1、本文档共6页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
使用QT进行内存管理收藏
Memory Management with Qt使用QT进行内存管理Garbage Collection through the Back Door通过后门垃圾回收Highly typed programming languages demand explicit (or at least implicit) creation of objects mentioning their types. They differ in how the objects are deleted: there are two approaches - direct deletion by the program or garbage collection by the language. 高级类型的语言要求对象创建时明确的(或者至少是隐式的)声明他们的类型。他们可以通过对象是如何销毁的来区别:有两种方法——通过程序直接销毁或者通过语言的垃圾回收机制。Explicitly deleting languages (eg. C++, Pascal) demand that the user knows when it is best to get rid of a dynamically created object. Garbage collected languages (eg. Java, SmallTalk) try to find out when an object is no longer used and automatically reclaim the memory. 明确的删除的语言(如,C++,Pascal)要求用户知道什么时候最好避免动态创建的对象。垃圾回收的语言(如java,Smaltalk)尝试找出什么时候一个对象不再被使用并自动的回收那部分的内存。Explicit deletion has the nice property that the programmer is in full control over the programs ressources - the amount of memory used and the amount and timing of CPU cycles spent on managing these ressources. 明确的删除的好处那就是程序员可以完全控制程序或者资源——使用的内存的大小和管理这些资源花费的cpu周期的大小和数量。Garbage Collection on the other hand takes a lot of responsibility off the programmer by keeping track on object references inside the system and freeing memory as needed. 另一方面垃圾回收通过在系统内部维持对象的属性的轨迹并且在必要时释放内存来分担程序员的一部分的职责
Default C++ Memory Handling默认的C++的内存处理C++ is a language that demands that the user deletes objects explicitly. There are three important strategies on how to handle this: C++是一种要求用户显式的删除对象的语言。在如何处理方面有三种重要的策略:Let the creating object delete its child objects. Let the last object to handle an object delete it. Dont care about memory and forget about it. 让创建的对象删除它的子对象。让最后的对象来控制一个对象来删除它。不关心内存并且忘了有这件事。
The last strategy is called memory leak and usually regarded as a bug. 最后的策略被称为内存泄露并且常常被认为是一个‘bug’The real problem with C++ is to find out which of the first two strategies is right and how to implement it. There are some cases in which the creating object is deleted much earlier than the chil
文档评论(0)