Is losing a link to dedicated memory for people using the Android app a big deal?

I believe that explaining the context associated with this problem will only confuse things, so I will be directly in pursuit:

If an Android application allocates a small portion of the internal memory via JNI, and then loses a reference to this memory (i.e. the variable refers to the objects that manage this own memory, it becomes zero and throws an exception with a null pointer if one attempts to use them):

  • Is it really important if this happens once and only once during the entire application life cycle?

  • Will the memory eventually be overwritten and thus be fixed?

I understand that this is bad practice allowing a memory leak. Honestly, I fully understand this. However, I also know that there are rare cases where a rule needs to be broken (to rephrase the words of Joshua Bloch from Effective Java). Sincerely, I do not want to discuss why I do this, I am only looking for an answer to this specific problem.

Thanks!!! Chris

+4
source share
2 answers

Is it really important if this happens once and only once during the entire application life cycle?

For most people, this will depend on what β€œa small part of your own memory” means to you. If we are talking about a few KB, then I would not have to worry about it when he lost once. If, on the other hand, we are talking about a few MB, things are probably different ...

However, the presence of a known memory leak is a sign of potential design problems, which may also cause other problems. It can also be a problem if future refactoring changes the architecture of the application.

Will the memory eventually be overwritten and thus be fixed?

Of course ... in the end. When the process is complete, the kernel will release all allocated resources. I am not very familiar with the internal development of Android, but I understand that processes are generally more durable than on the Linux desktop system. For embedded devices with little memory and no swap space, this can be a problem, especially if all application authors start memory leaks everywhere.

+2
source

Just don't do it. A memory leak is bad and prevents it easily.

0
source

All Articles