Unallocating direct buffer

I have a direct buffer that I eventually no longer need and set to null. This however does not free up the memory usage until I perform GC manually. Is there a way to forcefully free that memory automatically when im setting the buffer to null?
No description
9 Replies
JavaBot
JavaBotā€¢2w ago
āŒ› This post has been reserved for your question.
Hey @š“pothicon! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
0x150
0x150ā€¢2w ago
no, the gc does as the gc pleases a direct buffer is just a byte array in the end. you cant deallocate a byte array immediately the gc will free the memory when it's no longer needed. it's specifically engineered to do that. you dont need to worry about it if you do want to worry about it, you can just call upon the c standard library to malloc() and free() a pointer and use that to do your stuff (although i dont recommend doing that)
ayylmao123xdd
ayylmao123xddā€¢2w ago
you can call
System.gc();
System.gc();
it like suggests the garbage cleaner to work but does it as it pleases as mr 0x said
JavaBot
JavaBotā€¢2w ago
šŸ’¤ Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Daniel Santos
Daniel Santosā€¢2w ago
the java garbage collector has several levels of storage. the one that takes the most time to clean up is the permanent generation, where the objects that have been active for most time. If you can reduce the time the references to objects are kept (for example instead of reusing a buffer for several operations, create a new buffer for every single operation) those object will not survive long in the ephemeral generation and the memory usage may not be as large at any given instant
0x150
0x150ā€¢2w ago
with all due respect this advice is ass allocating and deallocating takes time. if need be for more memory, the gc will free everything it can. if you dont need to allocate and deallocate shit all the time, your program will run faster
ayylmao123xdd
ayylmao123xddā€¢2w ago
yea ig the best choice is to just try to somehow optimize this buffer or just trying to call
System.gc
System.gc
after ur done
š“pothicon
š“pothiconOPā€¢2w ago
ah so i dont have to worry about it technically having more memory allocated because it can still use it
JavaBot
JavaBotā€¢2w ago
šŸ’¤ Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Want results from more Discord servers?
Add your server