OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 10:00 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 20 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: Exceptions vs destructors
PostPosted: Thu Jul 30, 2015 5:17 am 
Offline
Member
Member

Joined: Wed Jun 03, 2015 5:03 am
Posts: 397
Rusky wrote:
Because all heap objects have an owner somewhere on the stack (directly or indirectly)

If an object was create in function main and the program exit is also in function main, then the object never will be released (only when program exits). It means it is possible to allocate something, to write a destructor for it, but because of an exception, the point, where the destructor is called, will be missed (may be even a thread will be killed, but program doesn't exit, main's stack is present and all it's referenced objects are alive).

Also, it can be said, that every object has an owner somewhere in the heap. But no automatic memory management system can determine if an object is still in use or not if a developer just forget to set the object's reference to null.

Generally speaking, the detection of a situation, when an object should be released, is not as simple as Rust designers think (only stack based deallocation is not enough).

_________________
My previous account (embryo) was accidentally deleted, so I have no chance but to use something new. But may be it was a good lesson about software reliability :)


Top
 Profile  
 
 Post subject: Re: Exceptions vs destructors
PostPosted: Thu Jul 30, 2015 12:23 pm 
Offline
Member
Member
User avatar

Joined: Wed Jan 06, 2010 7:07 pm
Posts: 792
Nope. An object owned on main()'s stack will be destructed when main() ends, regardless of whether that's through finishing the program or through unwinding. The only way around that is through an abort, which applies equally to finally blocks.

You can keep making things up, but RAII is an established way of managing memory and it has an answer to anything you can come up with.

_________________
[www.abubalay.com]


Top
 Profile  
 
 Post subject: Re: Exceptions vs destructors
PostPosted: Fri Jul 31, 2015 12:33 am 
Offline
Member
Member
User avatar

Joined: Thu Mar 27, 2014 3:57 am
Posts: 568
Location: Moscow, Russia
Personally, I always thought that automatic memory management is pretty simple. My compiler would insert code that would increment/decrement reference counters on getting/losing references. This is how ARC in Objective-C works.

_________________
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay


Top
 Profile  
 
 Post subject: Re: Exceptions vs destructors
PostPosted: Fri Jul 31, 2015 1:08 am 
Offline
Member
Member

Joined: Tue Nov 08, 2011 11:35 am
Posts: 453
Roman wrote:
Personally, I always thought that automatic memory management is pretty simple. My compiler would insert code that would increment/decrement reference counters on getting/losing references. This is how ARC in Objective-C works.
And how are you going to fight with circular references?


Top
 Profile  
 
 Post subject: Re: Exceptions vs destructors
PostPosted: Fri Jul 31, 2015 7:13 am 
Offline
Member
Member
User avatar

Joined: Thu Mar 27, 2014 3:57 am
Posts: 568
Location: Moscow, Russia
Nable wrote:
Roman wrote:
Personally, I always thought that automatic memory management is pretty simple. My compiler would insert code that would increment/decrement reference counters on getting/losing references. This is how ARC in Objective-C works.
And how are you going to fight with circular references?

As I understand, Objective-C (and other languages) solves this with "strong" and "weak" references.

_________________
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ]  Go to page Previous  1, 2

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 19 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group