5 ms·
Isn't not having garbage collection and advantage? I mean we have destructors which handle so much more than garbage memory. Close files, release mutexes, clo
by sqeaky 10y ago
Isn't not having garbage collection and advantage?
I mean we have destructors which handle so much more than garbage memory.
Close files, release mutexes, close sockets, cleanup thread pools, manage the lifetime of anything. One time I opened a web browser in the constructor and closed it in the destructor, and I had full confidence that no matter what crap happened in the middle my app never leaked whole browsers.
- thesmallestcat 10y agoMemory fragmentation? And alloc/free aren't free. So now you have to hack together your own memory management scheme and hope it performs well enough in both areas to be worth the extra effort and lost safety.
- matthewaveryusa 10y agoContemporary allocators make allocation cheap. Not sure how GC is any better at fragmentation.
- mrob 10y agoSome garbage collectors can move objects to remove fragmentation and update the pointers to them. eg: https://hacks.mozilla.org/2015/07/compacting-garbage-collection-in-spidermonkey/ https://hacks.mozilla.org/2015/07/compacting-garbage-collect...
- Impossible 10y agoIf you're thinking like that I don't see why you wouldn't prefer Java or C#? One of the major advantages of C and C++ is explicit memory allocation and lack of GC pauses.
- justin66 10y agoA person could wish for a more compact and lightweight runtime than what Java and .Net offer while still having GC. I imagine some of those people are checking out Go nowadays.
- netheril96 10y agoOracle's JVM have compacting GC that solves memory fragmentation, but Python and Ruby certainly do not. Python and Ruby interpreters also do a lot more dynamic allocations, so if memory fragmentation is ever a problem, they suffer worse.
- ygra 10y agoMost languages with garbage collection also have a mechanism for deterministic cleanup, e.g. IDisposable in C#, or AutoClosable in Java. That's because when dealing with external, or non-memory resources, deterministic release is a good thing. That doesn't mean that that scheme has to be the only option for memory allocations. Garbage collection has a lot of benefits, too.