Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is the concept of OOP intimately tied to allocating objects on the heap? Is it possible to write normal OOP without creating excessive objects on the heap?

share|improve this question

migrated from Jan 9 '13 at 19:21

This question came from our site for computer enthusiasts and power users.

up vote 2 down vote accepted

No, OOP has nothing to do with where objects reside in memory. For example, instances of the same class can be allocated statically, on the heap, or on the stack in C++. In other languages, like Python, memory management is almost transparent, so the question of location doesn't really apply.

share|improve this answer
Well, the question of location applies when you look at the implementation. And most implementations allocated practically everything dynamically (though the downsides are offset by tuning the way that memory is allocated). However, PyPy sometimes removes dynamic allocations completely (if the JIT compiler can prove they don't escape), and sometimes optimizes them (delays them, doing some work without touching the heap before allocating). – delnan Jan 9 '13 at 20:56
@delnan: Sure, different language & implementations of them can and will do things differently, but the answer to the OP's question is still that the concept of OOP is not intimately tied to allocating objects on the heap, even if it's commonly done. – martineau Jan 9 '13 at 21:25

Technically no, but "normal OOP" assumes dynamic allocation, for which a heap is a good general-purpose mechanism. You could certainly try using some other method, but you'd probably wind up re-inventing the heap.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.