answersLogoWhite

0

How is garbage collection done in c plus plus?

Updated: 8/9/2023
User Avatar

Muralimanohar

Lvl 1
14y ago

Best Answer

Garbage collection is used to released resources which were previously used by the application(s) which is called garbage collector. Garbage collection allows to prevent memory leaks which are the main problem of old style of programming.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

13y ago

Yes, I have come across libraries that do just that. Of the top of my head I cannot tell you where to look.

Answer: No. In C you cannot decide weather a piece of memory is still in use, or not. Of course you can write your own allocation/deallocation functions, with a 'deallocate everything' function.

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

C plus plus does not have a built-in garbage collector; you would need to write your own.

This answer is:
User Avatar

User Avatar

Wiki User

15y ago

There is no garbage collection in C

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

No such thing.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How is garbage collection done in c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Why c plus plus does not have garbage collector?

Although the C++ standard does not provide a garbage collector, there's nothing to stop you from using one. There are many garbage collection libraries available, or you can write your own. However, garbage collection is not required in C++ because correct use of resource handles and smart pointers ensures there is never any garbage to collect. More importantly, resource handles and smart pointers incur little to no overhead. Shared resource handles do incur some cost, but that cost is negligible compared to the cost of managing shared resources through "naked" C-style pointers, let alone the cost of garbage collection.


How garbage is collected?

Yes, GC can be considered as a JVM utility that checks the status of memory objects and cleans up all unused memory references so that, this memory can be used by other objects.


What you can do in C that connot be done by C plus plus?

Nothing. In C++ you could write a C compiler. So, everything that can be done with C, can be also done in C++.


Is C plus plus good for Embedded programming or not?

C and C++ programming is good for embedded programming. However, embedded implies long running, and that means the possibility of memory fragmentation. You will need to spend time working out or acquiring a method of memory management, such as the use of Smart Pointers and Garbage Collection. This is not a trivial task, but it is a necessary task.


Can graphics in C programming done with compilers other than turbo c plus plus?

Of course.


How do you avoid garbage values in c plus plus programs?

Initialization. Hint: your compiler might warn you, neverignore warnings if you aren't absolutely sure what they mean.


C plus plus uses dynamic memory management?

No, C++ does not use dynamic memory management. The programmer is entirely responsible for releasing dynamic memory when it is no longer required. When static objects fall from scope, their destructors are called automatically, but there is no automatic garbage collection for dynamic objects. Allocated memory remains allocated until the programmer manually releases it, or the thread that owns the memory is terminated.


Is it possible to convert java into c plus plus?

It is possible, however there are many caveats. For instance, Java utilises built-in garbage collection whereas C++ does not, so the resulting C++ will leak resources massively. The converted code should really be viewed as being a starting point -- you will have to manually edit the code in order to address all the problems created by the conversion. For a non-trivial application, manually editing the code would be highly prone to error.


In c garbage collector?

No.


What is a garbage collection in programming?

Garbage collection is a memory management technique where fragmented free memory blocks are coalesced into a smaller number of larger free blocks so as to satisfy a request for memory that is larger than any currently free block. This is done by moving non-free blocks around. The problem with doing that is that any existing pointers to those blocks become invalid, and need to be updated. Worse, if a thread is making changes to a block, a process called mutation, the act of moving the block can corrupt the block unless the move in done in a thread safe way. Presently, C and C++ do not support transparent garbage collection. Some vendors have implemented solutions, such as Microsoft's .NET/CLR. As an opposing example, Java is a managed environment also. In any case, using such an infrastructure requires changes to code, and you still need to consider thread safety.


What do you mean by initialisation of objects in c plus plus?

Initialization of objects means to provide an initial value for the object. This is usually done by the constructor, or it can be done with an assignment statement.


What is the syntax of clear screen in c plus plus?

It must be done by a platform-dependent function, it's "clrscr" from conio.h in TurboC