answersLogoWhite

0


Best Answer

You need to create the mainframe object on the heap so that the object does not go out of scope and get automatically deleted when your function exits. You could create it on the stack if the function doing that does not exit until everything is deleted, such as in the main loop of CWinApp. There are also issues with available memory in stack versus heap, as the stack size is preallocated while the heap can grow to the size of available memory.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Why it is required to create mainframe object on the heap?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Where string is stored on Heap or Stack in java?

A String is treated as an object, meaning there is an object on the heap. Of course, the variable you define is a pointer to the object, and it is stored on the stack.A String is treated as an object, meaning there is an object on the heap. Of course, the variable you define is a pointer to the object, and it is stored on the stack.A String is treated as an object, meaning there is an object on the heap. Of course, the variable you define is a pointer to the object, and it is stored on the stack.A String is treated as an object, meaning there is an object on the heap. Of course, the variable you define is a pointer to the object, and it is stored on the stack.


In Java where do instance variables stored in memory?

An instance variable is part of an object. Therefore, it gets stored together with the object, on the heap. The heap is the part of memory which is used to store objects.An instance variable is part of an object. Therefore, it gets stored together with the object, on the heap. The heap is the part of memory which is used to store objects.An instance variable is part of an object. Therefore, it gets stored together with the object, on the heap. The heap is the part of memory which is used to store objects.An instance variable is part of an object. Therefore, it gets stored together with the object, on the heap. The heap is the part of memory which is used to store objects.


Algorithm to delete?

The only way to delete objects in an object oriented programming language (unless they were created in heap memory) is for the object to go out of scope. If the object is declared in the heap, in c++ you would use delete[] ptr; or delete ptr; where ptr is a pointer to your object.


What are the arguments for and against Java's implicit heap storage recovery when compared with the explicit heap storage recovery required in C plus plus?

Sounds suspiciously like a homework question. :P


What is premain method in java?

A premain method is launch in java from jdk 1.5 for instrumentation. In a very simple world we can say that a premain method is used for get the size of the object resevered in heap area. It will return byte reserved by the object. This method is similar to the sizeOf() function of c/c++. In earlier version before 1.5 it was not possible to get the size of an object but after that you can get the bytes reserved by an object in heap with premain function.

Related questions

Where string is stored on Heap or Stack in java?

A String is treated as an object, meaning there is an object on the heap. Of course, the variable you define is a pointer to the object, and it is stored on the stack.A String is treated as an object, meaning there is an object on the heap. Of course, the variable you define is a pointer to the object, and it is stored on the stack.A String is treated as an object, meaning there is an object on the heap. Of course, the variable you define is a pointer to the object, and it is stored on the stack.A String is treated as an object, meaning there is an object on the heap. Of course, the variable you define is a pointer to the object, and it is stored on the stack.


In Java where do instance variables stored in memory?

An instance variable is part of an object. Therefore, it gets stored together with the object, on the heap. The heap is the part of memory which is used to store objects.An instance variable is part of an object. Therefore, it gets stored together with the object, on the heap. The heap is the part of memory which is used to store objects.An instance variable is part of an object. Therefore, it gets stored together with the object, on the heap. The heap is the part of memory which is used to store objects.An instance variable is part of an object. Therefore, it gets stored together with the object, on the heap. The heap is the part of memory which is used to store objects.


How Garbage collection flows and What is a heap memory?

Well, when you make an object, it is stored on the "heap". When that object has no reference variables, it is found by the garbage collector and deleted.


Algorithm to delete?

The only way to delete objects in an object oriented programming language (unless they were created in heap memory) is for the object to go out of scope. If the object is declared in the heap, in c++ you would use delete[] ptr; or delete ptr; where ptr is a pointer to your object.


What is the need of virtual destructor?

To ensure proper order of object distraction,it needed only when object constructed as Dynamically in Heap.


What are the arguments for and against Java's implicit heap storage recovery when compared with the explicit heap storage recovery required in C plus plus?

Sounds suspiciously like a homework question. :P


What is premain method in java?

A premain method is launch in java from jdk 1.5 for instrumentation. In a very simple world we can say that a premain method is used for get the size of the object resevered in heap area. It will return byte reserved by the object. This method is similar to the sizeOf() function of c/c++. In earlier version before 1.5 it was not possible to get the size of an object but after that you can get the bytes reserved by an object in heap with premain function.


What is the difference between binary heap and binomial heap?

The difference between Binomial heap and binary heap is Binary heap is a single heap with max heap or min heap property and Binomial heap is a collection of binary heap structures(also called forest of trees).


Do methods reside within an object?

ya methods resides within an object.. because if we declare a method static it can be called by object genration.. and static variables reside in heap known as permanent genration...


What is difference between heap memory and stack memory?

Difference between Stack vs Heap memory"Stack memory" and "Heap memory" are physically the same. The same chip of RAM may be used as stack memory when running one program and later used as heap memory when running some other program.The difference is in how they are used.StackOften a function or method calls another function which in turn calls another function etc.The execution of all those functions remains suspended until the very last function returns its value.All the information required to resume the execution of these functions is stored on the stack.In particular, local variables are stored on the stack.Local variables are often stored for short amounts of time while a function/method block uses them to compute a task.Once a function/method has completed its cycle, the space on the stack used by all local variables is freed.This chain of suspended function calls is the stack, because elements in the stack (function calls) depend on each other.The stack is important to consider in exception handling and thread executions.HeapHeapThe heap is simply the memory used by programs to store global variables.Element of the heap (variables) have no dependencies with each other and can always be accessed randomly at any time.All global variables are stored in heap memory.All variables dynamically created by the program with "new()" or "malloc()" or similar commands are also stored on the heap.In some programming languages, all instances of an object, including all the attributes of that instance, are stored on the heap.In those programming languages, local variables of a function that have object type are implemented as creating the new object on the heap,and storing a reference to that object in the local variable, which is on the stack.When that function exits, the heap memory used by each local variable that has object is freed, and then all the stack used by that stack is freed.ComparisonA Heap reference is also stored in Stack memory until the life cycle of the object has completed. Inside the Heap reference all the the contents of the object are stored whereas with a local variable only the variable contents are stored in the stack.Example:Stackvar bluevar redref 0x456783 (Heap reference)var tomref 0x498702 (Heap reference)var dianeHeap (0x456783)name => Susanage => 26city => Londonheight => 5'7sex => femaleHeap (0x498702)name => Paulage => 21city => Glasgowheight => 6'0sex => maleIn addition to heap memory and stack memory, a completely separate section of memory stores the constructors and other methods of a class/object.


What causes a memory leak?

A memory leaks can occur in a computer when a program on one's computer improperly manages the computer's memory allocations. This may happen when a object is stored but cannot be accessed by a running code.


What is system heap?

In programming, it refers to a common pool of memory that is available to the program. The management of the heap is either done by the applications themselves, allocating and deallocating memory as required, or by the operating system or other system program. Source: Answers.com