Step 3 and 4 are a waste of time. They provide no benefit and make the code potentially more buggy⦠as your step 4 indicates.
When you are more experienced, you will find in these simple cases you will just write things correctly the first time instead of having to redo it over and over.
You literally have absolutely no idea what you are talking about.
Your final solution does more work with the same amount of memory. You have no understanding at all of what the compiler is doing and if you were even on my team (ugh) Iād have to watch your coding practices like a hawk⦠because you are the worst kind of coder: you speak with authority on things you are clueless about.
We conducted many tests of performance and memory.[quote=ādanielp, post:27, topic:39048ā]
Doesnāt clear any memory - it drops a reference to memory thatās still being held by the object in the map, which would have happened as soon as your method exits anyway. The only way memory gets cleared in Java is when the GC runs and clears objects that are no longer referenced anywhere (or, more correctly, no longer reachable).
[/quote]
Yes, at last we have finalizer thread + gc. crashed by time(!).
It is easier to think in advance of such things.
You need to look for various low-level optimizations for java
Except that (a) these are micro-optimizations, which are almost certainly 100% of the time a bad idea in Java because they clutter your code and Javaās JIT will optimize everything on the fly and (b) none of them actually do what you think theyāre doing.
Doesnāt ācreate a variable.ā It assigns to a local variable āslotā that was allocated on the stack as soon as the method was called. Local variables are resolved at compile time and stack space is allocated once as soon as the method is entered.
Doesnāt allocate memory - it assigns a reference to preexisting memory to a variable. No new memory is allocated.
Doesnāt clear any memory - it drops a reference to memory thatās still being held by the object in the map, which would have happened as soon as your method exits anyway. The only way memory gets cleared in Java is when the GC runs and clears objects that are no longer referenced anywhere (or, more correctly, no longer reachable).
@pspeedās way is the most efficient and least error-prone by far.
Yes, but you have no idea what you are doing and so your conclusions will be incorrect with whatever you saw.
I mean, I know this 100% for a fact because you are so totally and completely wrong about this subject. Like, so obviously and totally and completely wrong. You have no idea what you are talking about and havenāt even bothered to look into it.
If you were on my team Iād be actively trying to get you fired.
Iāve been a software developer professionally for 27 years and run many many teams. You are the very worst kind of person to have on a team.
I think you are a lost cause but I will try to be clear.
(1) no memory is allocated here. Look at the byte code.
(2) no memory is cleared here. You are doing a wasteful stack operation by replacing the stack element with a null.
Moreover, you have needlessly leaked scope. By this idiom in general, you have potentially prevented the object from being GCāed at the end of the loop (if it was created in the loop⦠itās not here but the whole idiom you use is broken so I thought I would mention it).
You should keep loop-only variables inside the loop. Itās better for every reason and there are no down sides. The fact that you think there are means you do not understand what is actually happening.
No. My knowledge is based on actually knowing what is going on. Iāve looked at the compiler. Iāve looked at byte code. I do not need to guess because I can see the facts plainly.
i write a framework and service-market with 30-60 thousand users. I studied this at university for 5 years. I think im programmer in fact.
You just criticize my coding style.
Question⦠How does a blog post that has a laundry list of super high level items that comes across like the basic definition of what a bank does qualify your knowledge in the area of software development?