You are currently viewing Question about garbage collection.

Question about garbage collection.

I have been thinking a lot about memory management lately (New android developer), as phone’s have far less memory than a Desktop / Laptop.

Below are Two basic functions that perform the exact same arithmetic. One declares variables and the other does not.

My question seems obvious now that i’ve typed it out but…

Do both functions have the same impact on memory? Or does the exampleA take up more memory + trigger garbage collection, where exampleB does not?

Am i right to assume that, wherever possible, it is best to avoid variable declaration?

https://preview.redd.it/jjd29nrsnle91.png?width=1694&format=png&auto=webp&s=5024048316aa8088aadd20b0738c8beb169a67d4

submitted by /u/willor777
[link] [comments]