3 ms·
A novel and valid perspective. I have simply relied on leaking wildly before, knowing it's a small program that will end soon. It's an acceptable solution in s
by tempguy9999 7y ago
A novel and valid perspective.
I have simply relied on leaking wildly before, knowing it's a small program that will end soon. It's an acceptable solution in some cases.
- segfaultbuserr 7y agoAgree. The best way to manage memory in trivial, one-off C programs is not managing it at all. Don't try to free() everything. When I first started to write in C, I attempted to free() whenever I have a chance to, no matter how trivial the program is. Later a textbook convinced me that the effort is not worthwhile (unless for learning C) if all your program does is some simple calculation or processing.
- LadyCailin 7y agoThe JVM now has the epsilon GC, which does basically that, it just never GC’s. It’s unfortunate though that there’s no explicit way to tell java to free up a certain reference, if so, in combination with epsilon, you could write real time programs. Maybe you already can do something like that in the embedded java version though? Not sure.
- tempguy9999 7y agoInteresting. First I've heard of it. Well I guess if you can ensure bounded space by limited allocaton, then simply shove manually 'freed' stuff back on a free list, you could do that, sure. But a quick google gets https://openjdk.java.net/jeps/318 https://openjdk.java.net/jeps/318 which does say Non-Goals It is not a goal to introduce manual memory management features to Java language and/or JVM... but it doesn't say you can't or shouldn't. Game on then.
- LadyCailin 7y agoSure, if all your objects are mutable, then that can work, but a lot of stuff in core libraries are not, and you can’t control those allocations, short of not using them. There is also sun.misc.Unsafe, which has freeMemory, but first of all, I don’t know if that works for arbitrary addresses, or just ones previously allocated from the allocateMemory method, and anyways, I don’t think there’s a reliable way to get the address of an arbitrary object in the first place. But to add both of those pieces of functionality should be a pretty small patch to the jvm code anyways, so if someone were really motivated, it may not be all that much work anyways.
- tempguy9999 7y ago> and you can’t control those allocations You're totally right. Rather stupidly I hadn't thought of that.