Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to introduce Automatic Reference Counting (ARC) to C++?

Tags:

Objective C has introduced a technology called ARC to free the developer from the burden of memory management. It sounds great, I think C++ developers would be very happy if g++ also has this feature.

ARC allows you to put the burden of memory management on the (Apple LLVM 3.0) compiler, and never think about retain, release and autorelease ever again

So, if LLVM3.0 can do that, I think g++ also can free C++ developers from the tough jobs of memory management, right?

Is there any difficulties to introduce ARC to C++?

What I mean is: If we don't use smart pointers, we just use new/new[], is it possible for a compiler to do something for us to prevent memory leaks? For example, change the new to a smart pointer automatically?

like image 1000
camino Avatar asked Mar 16 '12 08:03

camino


1 Answers

C++ has the concept of Resource Allocation is Initialization(RAII) & intelligent use of this method saves you from explicit resource management.

C++ already provides shared_ptr which provides reference counting.

Also, there are a host of other Smart pointers which employ RAII to make your life easier in C++.

like image 57
Alok Save Avatar answered Oct 14 '22 19:10

Alok Save