面粉是什么做的| 鸿运当头什么意思| 头疼一般是什么原因引起的| 冰心的原名是什么| 荆棘是什么植物| 假牛肉干是什么做的| 验孕棒一条杠什么意思| 串门是什么意思| 属鼠是什么命| 炖羊肉放什么| 低gi是什么意思| 处暑是什么节气| 孩子总爱哭是什么原因| 牙齿痛吃什么消炎药| 抽筋吃什么药见效快| 甲鱼和什么不能一起吃| 梦见毒蛇是什么预兆| 三庭五眼是什么意思| yolo是什么| 经期吃什么水果好| 正官正印是什么意思| 吃什么容易得胆结石| 11月16日是什么星座| 翡翠什么样的好| 孕妇梦见黑蛇是什么意思| 眼睛皮痒是什么原因| zxj是什么意思| 三点水一个希读什么| 气场强大是什么意思| 丙氨酸氨基转移酶是什么意思| 虱目鱼在大陆叫什么| 为什么会长牙结石| 育婴师是干什么的| 左眼皮跳是什么意思| 71年猪是什么命| 阈值是什么意思| 精神洁癖是什么意思| affairs是什么意思| 宫颈鳞状上皮增生是什么意思| 日本什么时候开始侵略中国| 全性向是什么意思| 总出虚汗是什么原因| 手心红是什么原因| 儿童乘坐高铁需要什么证件| 宝贝什么意思| 腰痛是什么原因引起的| 切诺是什么药| 庚申五行属什么| 什么的杨桃| henry是什么意思| 恶风是什么意思| 食人鱼长什么样子| ldpe是什么材料| 李子不能和什么一起吃| 爬山带什么食物比较好| 2009属什么生肖| 林檎是什么意思| 蜜蜂为什么要采蜜| 喜欢紫色的人是什么性格| 芷字五行属什么| 为什么吃饱了就犯困| 懂事是什么意思| 黄芪和什么搭配最好| 白砂糖和冰糖有什么区别| 胳膊疼是什么原因| 人体缺钙吃什么补最快| 健康证照片用什么底色| 6.27什么星座| 超前点映什么意思| 10年是什么年| 庙会是什么意思| 按摩脸部有什么好处| 为什么身上会痒| 起飞是什么意思| 右乳导管扩张什么意思| 三叉神经痛挂什么科| 麻古是什么| 牙齿有裂纹是什么原因| 什么叫屈光不正| 蚊子咬了涂什么| 夏至要吃什么| 路痴是什么原因造成的| 黄芪的功效与作用是什么| 三不伤害是指什么| 重楼的别名叫什么| 郡字五行属什么| 无花果什么功效| 阴骘是什么意思| 吴亦凡为什么退出exo| 月经推后是什么原因| 卵巢早衰吃什么可以补回来| 为什么睡觉会突然抖一下| 男孩流鼻血是什么原因| 什么样的孙悟空| 盥洗是什么意思| 梦见女婴儿是什么意思| 什么是脂溢性脱发| 流鼻涕打喷嚏吃什么药| 哈欠是什么意思| 三虫念什么| 心理疾病吃什么药| 荔枝什么品种好吃| 黄豆吃多了有什么坏处| 寂静的意思是什么| 脂肪肝是什么| 心愿是什么意思| 胸痛是什么病的前兆| 长期喝蜂蜜有什么好处| 扁平疣是什么样子图片| 雨霖铃是什么意思| 颈动脉硬化有什么症状| 卧龙凤雏什么意思| 阴气重是什么意思| 富硒对人体有什么好处| 龋坏是什么意思| 丑小鸭告诉我们一个什么道理| 为什么腋下老是出汗| 海外是什么意思| 生吃大葱有什么好处和坏处| 一什么粽子| 什么叫根管治疗牙齿| 水粉是什么| 备孕需要做什么准备| 社保断了有什么影响| 睡不着挂什么科| 帝舵手表什么档次| 原发性高血压是什么意思| 孕妇梦见猫是什么意思| 南枝是什么意思| 多出汗是什么原因| 气场是什么意思| 卢森堡为什么那么有钱| 备孕什么意思| 2008年是什么年| 孕反什么时候结束| 七月上旬是什么时候| 白头翁是什么动物| 检车需要什么手续| 男女身份证号码有什么区分| 大腿内侧什么经络| 孕妇吃什么盐最好| 缺维生素D吃什么补得最快| 吃什么养心| 什么是湿热| 毒龙是什么意思| 35岁属相是什么生肖| 羊蛋是什么部位| 品牌logo是什么意思| 奥特莱斯是什么店| 季付是什么意思| 碱性体质的人有什么特征| 吃什么东西排酸最快| 失眠去医院挂什么科| 口腔溃疡反复发作是什么原因| 美国为什么有哥伦比亚| 奇美拉是什么| 80岁是什么之年| 清谈是什么意思| 胃胀是什么症状| 走马观花是什么意思| 动员是什么意思| 胃一阵一阵的疼是什么原因| 褥疮用什么药膏最好| 水仙茶属于什么茶| 胃胀吃什么药效果最好| 若无其事的若是什么意思| 斯里兰卡属于什么国家| 胎位 头位是什么意思| 皈依有什么好处| 正襟危坐什么意思| 睡眠不好用什么药调理| 盛夏是什么时候| 为什么直系亲属不能输血| 属兔什么命| 反骨是什么意思| 转氨酶高吃什么食物好| 阳阴阳是什么卦| 心咒是什么意思| 冰箱什么牌子好| 史迪奇是什么动物| 恋恋不舍的意思是什么| 小孩什么时候长牙| 栀子花什么时候开| 6s管理内容是什么| 肠胃炎引起的发烧吃什么药| 睫角守宫吃什么| 益母草什么时候喝最好| 36年属什么生肖| 非你不可什么意思| 两个虎是什么字| 梦见大水是什么预兆| palladium是什么牌子| 脑梗有什么特效药| 没主见是什么意思| 车辙是什么意思| 企鹅是什么动物| bone什么意思| 小孩子拉肚子吃什么药| 什么是乙肝病毒携带者| 大便有血是什么原因男性| 丢包率是什么意思| 腕管综合征挂什么科| 85年属什么的| 闭门思过是什么意思| 这个季节吃什么水果| 淋巴结回声是什么意思| 胸口疼痛什么原因| 蜘蛛代表什么生肖| 吃什么能提高代谢| 头发分叉是什么原因| 乙肝表面抗原阴性是什么意思| 阴险是什么意思| 梦见自己生男孩是什么意思| 曹操是什么样的人| 吃什么长高| 京东自营店是什么意思| 下眼皮跳是什么原因| 合肥有什么好吃的| 红细胞压积偏低是什么意思| 9岁属什么生肖| 党参泡酒有什么功效| 头发热是什么原因| 甲亢可以吃什么| 时髦是什么意思| 宝宝打嗝是什么原因引起的| 小孩为什么经常流鼻血| 咳嗽发烧是什么原因| 脑梗有什么症状| 宫寒应该吃什么怎样调理| 为什么姨妈会推迟| 什么情况下需要做宫腔镜| 狗狗胰腺炎有什么症状| 血糖高去医院挂什么科| 黑芝麻不能和什么一起吃| 肚子疼拉肚子挂什么科| 嘴唇肿起来一般是什么原因引起的| 发泥和发蜡有什么区别| 紧张手抖吃什么药| 胆结石吃什么水果好| mm是什么意思| 路上行人匆匆过是什么歌| 脾胃虚寒吃什么食物| 女性更年期潮热出汗吃什么药| 香港有什么好吃的| 性激素是什么| 紫菜和海带有什么区别| 珊瑚粉是什么颜色| 白醋加盐洗脸有什么好处| 风水宝地是什么意思| 不以规矩下一句是什么| 细菌性结膜炎用什么药| 静脉曲张挂什么号| 蜂蜜不能和什么一起吃| 减肥可以吃什么| 什么的雾霾| 脑梗前有什么预兆| 海胆是什么| 钺读什么| 什么水果糖分低| 属猴与什么属相最配| 胃阳虚吃什么中成药| 装模作样是什么生肖| 乌合之众什么意思| 心五行属性是什么| 百度Jump to content

码上有缘手机版(手机码上有缘安卓版下载)V1.1官方版

From Wikipedia, the free encyclopedia
百度 发现消极对待客户、骂客户、售后不及时处理,一次罚款100元,再者无薪辞退。

In object-oriented programming (OOP), object lifetime is the period of time between an object's creation and its destruction. In some programming contexts, object lifetime coincides with the lifetime of a variable that represents the object. In other contexts – where the object is accessed by reference – object lifetime is not determined by the lifetime of a variable. For example, destruction of the variable may only destroy the reference; not the referenced object.

Terminology

[edit]

Aspects of object lifetime vary between programming languages and within implementations of a language. The core concepts are relatively common, but terminology varies. For example, the concepts of create and destroy are sometimes termed construct and destruct and the language elements are termed constructor (ctor) and destructor (dtor).

Determinism

[edit]

Creation of an object is generally deterministic, but destruction varies by programming context. Some contexts allow for deterministic destruction, but some do not. Notably, in a garbage-collection environment, objects are destroyed when the garbage collector chooses.

The syntax for creation and destruction varies by programming context. In many contexts, including C++, C# and Java, an object is created via special syntax like new typename(). In C++, that provides manual memory management, an object is destroyed via the delete keyword. In C# and Java, with no explicit destruction syntax, the garbage collector destroys unused objects automatically and non-deterministically.

An alternative and deterministic approach to automatic destruction is where the object is destroyed when code decrements the object's reference count to zero.

With an object pool, where objects may be created ahead of time and reused, the apparent creation and destruction of an object may not correspond to actual. The pool provides reinitialization for creation and finalization for destruction. Both creation and destruction may be non-deterministic.

Objects with static memory allocation have a lifetime that coincides with the run of a program, but the order of creation and destruction of the various static objects is generally non-deterministic.

Life cycle

[edit]

Object life cycle refers to the events that an object experiences including and between creation and destruction.

Life cycle generally includes memory management and operations after allocation and before deallocation. Object creation generally consists of memory allocation and initialization where initialization includes assigning values to fields and running initialization code. Object destruction generally consists of finalization (a.k.a. cleanup) and memory deallocation (a.k.a. free). These steps generally proceed in order as: allocate, initialize, finalize, deallocate.

Based on programming context, these steps may be partially or fully automated, and some of the steps can be customized.

The frequency of customization tends to vary by step and programming context. Initialization is the most commonly customized step. Finalization is common in languages with deterministic destruction, notably C++, but rare in garbage-collected languages. Allocation is rarely customized, and deallocation generally cannot be customized.

Creation

[edit]

The way to create objects varies across programming contexts. In some class-based languages, a constructor handles initialization. Like other methods, a constructor can be overloaded in order to support creating with different initial state.

Destruction

[edit]

Generally, an object is removed from memory after it is no longer needed. However, if there is sufficient memory or a program has a short run time, object destruction may not occur; memory simply being deallocated at process termination.

In some cases, object destruction consists solely of deallocating memory, particularly with garbage-collection, or if the object is a plain old data structure. In other cases, cleanup is performed prior to deallocation, particularly destroying member objects (in manual memory management), or deleting references from the object to other objects to decrement reference counts (in reference counting). This may be automatic, or a special destruction method may be called on the object.

In class-based languages with deterministic object lifetime, notably C++, a destructor is called when an instance is deleted, before the memory is deallocated. In C++, destructors differ from constructors in various ways. They cannot be overloaded, must have no arguments, need not maintain class invariants, and can cause program termination if they throw exceptions.

With garbage collection, objects may be destroyed when they can no longer be accessed by the program. The garbage-collector calls a finalizer before memory deallocation.

Destroying an object will cause any references to the object to become invalid. With manual memory management, any existing reference becomes a dangling reference. With garbage collection, objects are only destroyed when there are no references to them.

Consistency

[edit]

Object lifetime begins when allocation completes and ends when deallocation starts. Thus, during initialization and finalization, an object is alive, but may not be in a consistent state. The period between when initialization completes to when finalization starts is when the object is both alive and in a consistent state.

If creation or destruction fail, error reporting (for example, raising an exception) can be complicated since the object or related objects may be in an inconsistent state.

For a static variable, with lifespan coinciding with the program run, a creation or destruction error is problematic since program execution is before or after normal execution.

Class-based programming

[edit]

In class-based programming, object creation is also known as instantiation (creating an instance of a class). Creation and destruction can be customized via a constructor and a destructor and sometimes with separate initializer and finalizer methods.

Notably, a constructor is a class method as there is no object (instance) available until the object is created, but destructors, initializers, and finalizers are instance methods.

Further, constructors and initializers often can accept arguments, while destructors and finalizers generally do not as they are often implicitly callable.

Resource management

[edit]

In languages with deterministic lifetime objects, lifetime may be used to piggyback resource management. This is called the Resource Acquisition Is Initialization (RAII) idiom. Resources are acquired during initialization, and released during finalization. In languages with non-deterministic lifetime objects (i.e. garbage collected), the management of memory is generally kept separate from management of other resources.

Examples

[edit]

C++

[edit]

A C++ class can be declared with defaults as:

class Foo {};

When declared in an automatic context, the object is destroyed at the close of the block it is declared.

int bar() {
  Foo foo;
  // foo is destroyed here
}

When created dynamically, it lives until it is explicitly destroyed.

int bar() {
  Foo *pFoo = new Foo();
  delete pFoo;
}

Java

[edit]

A Java class can be declared with defaults as:

class Foo {}

After an instance is created (i.e. new Foo()) it lives until it has no references and the garbage collector deletes it.

Rust

[edit]

Rust uses lifetime annotations to declare the lifetime of arguments passed into a function. The lifetime is declared in the function signature within angle brackets. In this example a reference to the struct File is passed into the example function with the lifetime annotation 'a.

fn example<'a>(file: &'a File) {
    // ...
}

References

[edit]
马不停蹄是什么生肖 手指尖麻木是什么原因 滑膜炎是什么病 拉杆箱什么材质好 红棕色是什么颜色
震仰盂什么意思 为什么医生说直肠炎不用吃药 缺铁性贫血吃什么食物 介入超声是什么意思 36岁生日有什么讲究
肝郁化火吃什么中成药 羽字属于五行属什么 梦见麒麟是什么兆头 嗓子痛吃什么好 加速度是什么意思
脸麻是什么原因 初伏吃什么 番薯是什么 柯字五行属什么 听字五行属什么
季付是什么意思hcv9jop3ns6r.cn 下面潮湿是什么原因引起的hcv8jop3ns5r.cn 阴毛有什么作用hcv9jop6ns2r.cn 夏天喝什么汤最好hcv8jop5ns5r.cn 头发沙发是什么意思hcv9jop2ns0r.cn
糖料病者应吃什么好hcv8jop7ns3r.cn 吃什么可以快速美白aiwuzhiyu.com 肝结节是什么病严重吗hcv9jop5ns9r.cn 梦见自己鼻子流血是什么预兆hcv7jop6ns8r.cn 户主有什么权利yanzhenzixun.com
年轻人手抖是什么原因hcv9jop6ns6r.cn bella是什么意思hcv8jop7ns9r.cn 什么是疣hcv9jop5ns7r.cn 脑膜炎是什么病严重吗hcv7jop9ns4r.cn 一月份什么星座hcv7jop6ns3r.cn
盲人按摩有什么好处hcv8jop4ns3r.cn soleil是什么意思hcv8jop5ns1r.cn 鼻炎流鼻血是什么原因hcv8jop8ns0r.cn 绿豆长什么样hcv8jop9ns4r.cn 血脂稠吃什么药hcv7jop9ns2r.cn
百度