azharrahi
March 7th, 2009, 07:34 AM
Hello
Hope all will be fine here.
I want to know why objects are created on heap? what is the benefit of it? cant we manage objects over stack? if not then why?
Thanks
ProgramThis
March 10th, 2009, 12:30 PM
Of course you can manage items on the stack. The stack is generally used every time you make a function call and declare local variables used in that function.
You would use the heap of you had a data structure that was sufficiently large (being as the stack will cause, you guessed it, stack overflow if you exceed the size limits).
Also, elements on the stack disappear, they are temporary. Elements on the heap are there for the life of the program (static, global variables).
dalant019
March 29th, 2009, 01:50 AM
Objects can be created on heap or stack. It depends on the rule of languages(compilers).