answersLogoWhite

0


Best Answer

Be more specific with your question:

Java: deallocation is always automatic

C++: objects allocated with new have to be released with delete

User Avatar

Wiki User

15y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Do you need to deallocate memory when an object is not in use?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

This key word causes an object to be created in memory?

To instantiate a object, we use the new keyword in Java, which creates an object in memory.


What is the purpose of using new and delete operations?

New and delete are akin to malloc and free, respectively, in C. Although both malloc and free are still available in C++ (for backward compatibility and interoperability with C-style code), the new and delete operators are much simpler to use because the allocation and deallocation of all dynamic memory consumed by an object is handled by the object's own constructors and destructors. Thus there is no need to calculate how much memory to allocate; the new operator can work that out all by itself, based upon the class of object being instantiated, and the object itself can allocate/deallocate any additional dynamic memory as and when it actually requires it. This mechanism of construction/destruction allows highly complex dynamic objects and object hierarchies to be instantiated at will with just a single call to the new operator. Each object takes care of itself (as do all embedded objects and/or base classes of the object), thus all the programmer has to do is instantiate and delete an object as and when required.


What is the need of array variables?

congugative memory allocation ,is use to array


How do you use set and get in object-oriented programming?

A set function (or setter) is an object mutator. You use it to modify a property of an object such that the object's invariant is maintained. If the object has no invariant, a setter is not required. A get function (or getter) is an object accessor. You use it to obtain a property from an object such that the object's invariant is maintained. If the object has no invariant, you do not need a getter.


Difference between object declaration and object creation?

Declaration of the object involves only creating the reference variable to the object. Example: class SampleClass{ } Object Declaration: SampleClass obj1; Object Creation: Creating an object involves use of new keyword and actually allocating memory for that object. SampleClass obj2 = new SampleClass ();

Related questions

Which keyword do you use to deallocate memory that has been assigned to a stream object?

Delete keyword


This key word causes an object to be created in memory?

To instantiate a object, we use the new keyword in Java, which creates an object in memory.


Dangling reference in java?

I think you're referring to the C/C++ concept of "dangling pointers." This is when you allocate some memory to a pointer, then deallocate that memory, but don't change the pointer. This causes any attempted use of the pointer to return an unused memory address. There is no such concept in Java, since the programmer has little to no control over how memory is allocated or freed. The closest thing I can think of is if you're using a class such as a Reader, in which you can close the object (Reader.close()) and then still have a reference to it. But in this case (and other similar cases) attempting to use the Reader further will result in an IOException being thrown.


What is the purpose of using new and delete operations?

New and delete are akin to malloc and free, respectively, in C. Although both malloc and free are still available in C++ (for backward compatibility and interoperability with C-style code), the new and delete operators are much simpler to use because the allocation and deallocation of all dynamic memory consumed by an object is handled by the object's own constructors and destructors. Thus there is no need to calculate how much memory to allocate; the new operator can work that out all by itself, based upon the class of object being instantiated, and the object itself can allocate/deallocate any additional dynamic memory as and when it actually requires it. This mechanism of construction/destruction allows highly complex dynamic objects and object hierarchies to be instantiated at will with just a single call to the new operator. Each object takes care of itself (as do all embedded objects and/or base classes of the object), thus all the programmer has to do is instantiate and delete an object as and when required.


If you buy a solid state hard drive does your computer use it as memory too?

You can use it for virtual memory,but you need memory still.


Do smartphone use memory cards?

No the memory is built in but you need a sim card


Can you use a usb hard drive as a memory card in ps2?

No you need the memory card


Does the PSP need a memory card?

The SONY PSP doesn't necessarily need a Memory Card to function. And by function i mean to play a game or use the Internet but up to now SONY PSP's are sold with no internal memory which means if you want to have Pictures, Videos, Music, and save game data you need to have a memory card. So basically you need the memory card if you want to use the PSP to its intended use.


do i need usb flash memory to download quick books?

No need to use usb flash memory to download quick books.


Do you have to install software on your computer to use a memory card reader?

The driver software will need to be installed to use your memory card software.


What types of memory cards don't need a reader to use?

The only memory cards you wouldn't need a reader for are ones you would never need to connect to a computer. By definition, memory cards need a reader to be connected to a computer.


What is Random Access Memory and how is it use?

I Need Help on This One