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

  • Learning Rust
  • Paul Johnson Vesa Kaihlavirta
  • 138字
  • 2021-07-02 23:07:26

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.

主站蜘蛛池模板: 罗山县| 温州市| 临邑县| 巴里| 定结县| 柞水县| 河间市| 阳新县| 偃师市| 闽清县| 东海县| 阳原县| 普安县| 江源县| 乌什县| 琼结县| 昌乐县| 塘沽区| 宁津县| 江安县| 兴安盟| 波密县| 潜山县| 普陀区| 景洪市| 苏州市| 吉首市| 句容市| 双辽市| 郎溪县| 济阳县| 义乌市| 海门市| 内黄县| 卫辉市| 昭觉县| 壤塘县| 碌曲县| 梅州市| 鄂托克前旗| 法库县|