Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a question on recursion , what are the efficiencies and inefficiencies of recursion , I know it will use more memory but is it good to use it and when to use it?
It depends on the size of the objects you are recursing.
If you are doing recursion over objects that are already in memory, memory impact will be neglible because it's simply using the same objects that are already in memory over and over. Just see which objects/variables you can re-use to keep memory footprint low.
If you are recursing over directories/files etc.. and constantly loading stuff from disc or database that is not in memory yet, it can become very expensive to do so because of the loading, allocating and then processing.
It all depends on what you really are doing... and you haven't provided much detail.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have a requirement where I read string from huge file and process it in HashMap. I want to throw exception when HashMap size is > 5GB. How do I set the max memory size of HashMap?
You subclass HashMap and override methods to keep track of what is allocated and freed, and throw the exception yourself.
However, be aware that determining how much memory an object occupies is itself a significant task... how deep do you go if the object contains references to other objects?
This is a non-trivial problem of deciding what you mean and what you want to track. There is no one-size-fits-all answer.
And, as suggested by #ModusTollens in a comment, this is likely an XY Problem.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Why getText() in JPasswordField was deprecated?
According to this answer for the above question, what I understood was that creating a String object containing the password is a security threat because it may remain in the memory for a while and it is immutable.
So I was wondering,
How easy is it to retrieve something which has been hanging around
in the memory, without a reference or left out for garbage collection?
And how do you do it?
EDIT
As the question has been closed, be kind to share your knowledge by adding a comment, and consider reopening the question if you believe it may get interesting answers in the future. :)
https://en.wikipedia.org/wiki/Heartbleed
This is a good real-world example of things hanging in memory being used for exploitation. There's different ways to do it, so it's good to just make sure things that are valuable aren't being left hanging. Usually these attacks are just guess-and-check. You just keep sending information and piecing together the bits of extra memory you get in return.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I understand we can do this with file input and output, but why would we want to do this?
It is simply called persistence.
You nailed it: you want to be able to store information (for example after intensive computations) in a way that survives the lifetime of the current JVM process.
In that sense serialization is a (poor) version of database storage.
But of course, that comment is correct: this does not prevent the creation of objects. It is a mechanism to resurrect previous state into "new" objects.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
There are several methods to create Instance in Java
(Different ways are new operator, cloning, reflection and DE-serialization etc)
So among them which is the fastest of all ?
In such a case fastest means which one of those executes less operations before actually allocating the memory for the object. It is easy to determine that new is the fastest among those because it doesn't bear the overhead created from the others such as clone etc.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I need to measure memory usage some sort of method. I can get Heap and nonHeap Memory size using mxBean.getHeapMemoryUsage and mxBean.getNonHeapMemoryUsage.
My question is how do we caclulate memory usage in specific method execution? (Only consider HeapMemory or both)
You should consider only HeapMemory and not NonHeapMemoryUsage. NonHeapMemory is where Java Virtual machine keeps method codes and classes byteCode stuffs.
Here is helpful link get OS-level system information
Note: you should consider stack memory as well, but that is very less compare to heap memory used by methods or class objects.