官术网_书友最值得收藏!

Deallocation

Unlike when memory is freed up on the stack, when you deallocate memory from the heap, you end up with holes in the heap. These are empty and can be reallocated to other variables. As with anything to do with memory, the reallocation is handled by the OS.

Deallocation is handled automatically by Rust with a style typically called Resource acquisition is initialization. This confusingly named concept means that resources (such as heap memory, but also other things such as file pointers) are allocated during object creation and released during object destruction. Object destruction in Rust happens when the binding goes out of scope. If you need to define custom destructors for your own objects, you can implement the std::ops::Drop() trait. It contains a single method, drop, which gets called when your object loses its last binding.

主站蜘蛛池模板: 长治县| 若羌县| 成安县| 洛宁县| 辽阳市| 清水河县| 梁平县| 大连市| 兴安县| 府谷县| 新干县| 沈丘县| 崇文区| 阿巴嘎旗| 黄山市| 溧阳市| 东宁县| 威信县| 淳化县| 房产| 驻马店市| 九台市| 即墨市| 绵阳市| 登封市| 临桂县| 石狮市| 额济纳旗| 陕西省| 东阿县| 涿州市| 平武县| 高碑店市| 红原县| 黑龙江省| 凉城县| 军事| 普安县| 桐乡市| 水城县| 香河县|