There are at least two distinct memory management models:
Java (we do it for you)
C++ (it is your responsibility)

I have two questions:
(1) Is GC language specific or compiler specific?
(2) Do most languages fall in one of these two categories? Are there other memory models in commonly used languages?

The names of the language and corresponding memory management model would answer this question.

closed as too broad by kevin cline, Ixrec, Robert Harvey, gnat, Nicol Bolas Jun 24 '16 at 3:23

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    Did you read the Wikipedia article on garbage collection? Why not? – kevin cline Jun 23 '16 at 22:36
  • (1) Yes. (2) Yes. – Robert Harvey Jun 23 '16 at 23:07
  • 2
    Your terminology is confusing. Garbage collection is entirely in the first camp ("we do it for your"), if memory is managed manually then it's not GC. – user7043 Jun 23 '16 at 23:08
  • I read Wiki. It doesn't have an answer to my question. I didn't know that I should prefer Wiki over peer reviewed Programmers.SE. – sixtytrees Jun 23 '16 at 23:35
  • 3
    That's ... not really what this is about. When you go to a professional programming website, the participants expect you to already know some fundamentals about what you are asking. Consequently they expect you to have already done some basic research before asking your question. – Robert Harvey Jun 23 '16 at 23:38

C++ doesn't have a manual approach to memory management at all. If you're calling free in C++, you're using it wrong. That's the C way that we're proud to be disowning.

Really, the predominant models are non-deterministic (GC), deterministic (C++, D), and manual (C).

  • Meh. Safe pointers are just window dressing for bare pointers, that someone only had to write once. Garbage collection is merely a different form of window dressing, except that it's actually a first-class language construct. – Robert Harvey Jun 23 '16 at 23:54
  • 3
    Or, to put it another way, "Don't be too proud of this technological terror you've created..." – Robert Harvey Jun 23 '16 at 23:58
  • 1
    Two things to look at, I'm not familiar enough with either to fin give a full answer, but maybe others will. First, Apple's Objective-C and Swift use automatic reference counting (ARC). Second, the new Rust programing language uses a rich model of bindings and borrowing. – Erik Eidt Jun 24 '16 at 0:06
  • 1
    @RobertHarvey: The whole problem with manual memory management is the duplication. If you only had to do it once for all usages in all programs (e.g. unique_ptr) it would be totally fine. – DeadMG Jun 24 '16 at 16:15
  • @ErikEidt - Indeed, Rust provides the deterministic memory management as DeadMG described it but as a first-class construct like Robert Harvey appears to want it to be. – Jules Jun 24 '16 at 23:11

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