Rule 90/10 for memory management?

Most programmers agree that garbage collection is a great thing, and in most applications it costs overhead. However, my personal observation is that the memory management for most objects is trivial, and perhaps 10% -20% of them take into account the need for codes, such as reference counting and really complex memory management schemes in general. It seems to me that you can get all the benefits of garbage collection with only a small fraction of the overhead by conservatively deleting large objects manually when the lifetime of the object is obvious and allows the GC to collect the rest, assuming that the GC implementation supports such a thing. This would allow the GC to work much less often and consume less excess memory, while avoiding cases that are actually difficult to manage manually. It would be even more interestingif the compiler automatically entered deterministic delete operators, where the lifetimes were obvious:

int myFunc() {
    Foo[] foo = new Foo[arbitraryNumber];  // May be too big to stack allocate.
    // do stuff such that the compiler can prove foo doesn't escape.
    // foo is obviously no longer needed, can be automatically deleted here.
    return someInteger;
}

Of course, this may not work with the copying GC, but for the sake of this post, let me assume that our GC does not copy. Why are such hybrid memory management schemes seemingly so rare in major programming languages?

+5
source share
7 answers

Because this case is too rare. Almost no method is isolated. They all accept objects from the outside or create objects and transmit them.

A method that does not have access to any fields, has no parameters and returns nothing, cannot do anything.

, GC (90%) 90% ( ). , , . ( , ).

GC . , . Java 5 GC Performance Tuning . , , GC .

: GC , . , . (, 90% ), (10%). , , , , . , , ) ; 40 100 , ) , .

+3

" , - , ".

...

+2

" ": ;)

[...]
Foo() {
    someGlobalList.add(this);
}
[...]

, , , . , , , (, using #, , , ). , , .

+1

, , GC . - GC.

, , . (, -, ).

+1

, , , , , . , # struct, class. , , , , .

, , , , .

, , stackalloc .

0

, D . , , , GC malloc/free. scoped, , , , , .

0

, , , , , , , . , , GC, , , - . , , undefined; GC . , - , , GC, , .

, "-", . , , gen0 gen1. , . , , , "", .

0

All Articles