Cleanup总结---Thinking in java 英文版部分小结
来源:互联网 发布:php支付宝服务端demo 编辑:程序博客网 时间:2024/05/22 19:20
Initialization&Cleanup
Cleanup: finalization and garbage collection
1.Your objects might not get garbage collected.
2.Garbage collection is not destruction.
3.Garbage collection is only about memory.
The garbage collector only knows how to release memory allocated with new, so it won’t know how to release the object’s “special” memory.
finalize( ): It turns out that the need for finalize( ) is limited to special case in which your object can allocate storage in some way other than creating an object.
This can happen primarily through native methods (固有方法), which a way to call non-java code from java (do something C-like).
Eg:call free( ) (a C and C++ function) in a native method inside your finalize( ).
If any potions of the object are not properly cleaned up , than you have a bug in your program that can be very difficult to find. finalize( ) can be use to eventually discover this condition, even if it isn’t aways called.
Eg:TerminationCondition.java
//initialization/TerminationCondition.java//Useing finalize() to detect an object an object that//hasn't been properly cleaned upclass Book {boolean checkedOut = false;Book(boolean checkOut) {checkedOut = checkOut;}void checkIn() {checkedOut = false;}protected void finalize() {if (checkedOut) System.out.println("Error: checked out ");//output tag//you can also do this ://try {//super.finalize();//System.out.println("Error: checked out too");//output tag//} catch (Throwable e) {////do nothing//}}}public class TerminationCondition {public static void main (String[] args) {Book novel = new Book(true);novel.checkIn();new Book(true);System.gc();//force finalization}}
- Cleanup总结---Thinking in java 英文版部分小结
- thinking in java(III)--initialization and cleanup
- Thinking in Java(7)-Guaranteeing proper cleanup
- Thinking in Java(8)-inheritance and cleanup
- 看了thinking in java 的initialize and cleanup 的一点总结
- 《Thinking in Java》总结
- 【学习笔记】Thinking in java (第三版)第四章 初始化和清除(Initialization & Cleanup)
- 开始读英文原著Thinking in java
- Thinking in java 异常总结
- Thinking in Java第二章阅读小结
- Thinking in Java第四章阅读小结
- Thinking in Java第五章阅读小结
- Thinking in Java第六章阅读小结
- Thinking in Java第七章阅读小结
- Thinking in Java---泛型小结
- 处理教材:Initialization & Cleanup of "Thinking in Java"
- 【资源】Thinking in java 4th edition 英文版 高清晰pdf+源代码+练习题答案
- Thinking in java的简单总结
- 应用Yii1.1和PHP5进行敏捷Web开发12
- 应用Yii1.1和PHP5进行敏捷Web开发13
- [OpenWrt] openwrt的一些琐事
- 应用Yii1.1和PHP5进行敏捷Web开发14
- live555源代码研究——RTSP服务器端建立及监听
- Cleanup总结---Thinking in java 英文版部分小结
- UVa 12266 Stock Prices (优先队列)
- Oracle中存储过程和函数的比较
- 【eclipse设置】Eclipse使用入门教程
- dos下实现延迟功能
- Activity跳转与传值
- setsocketopt设置socket应用
- 排序算法
- vs2008 无法设置断点&设置内存断点的方法