I know that it is best practice to release a wake_lock
as soon as it is no more needed, but what happens if the Activity
or Service
, for example, that has acquired it finishes or is stopped before you release the lock? Is it automatically released by the system? I think the system should release them automatically in that case, but I can not find anything on the API docs..
EDIT: added more info
Looking at the PowerManager.WakeLock
documentation, I've seen that the wake_locks are reference counted by default (read setReferenceCounted
here), i.e. if we retrieve a wake lock in an activity with PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "myWakeLock"); wl.acquire();
and then the reference variable wl
that holds it goes out of scope, then the wake lock is released because its reference count goes to zero... is it right?
EDIT: wrong understanding above
I think I've misunderstood the reference count concept above... it should mean that if I acquire twice the lock and release it only once, then the reference count is 1 and the lock is not yet released. If it is not reference counted, then I can acquire x times and then with a single release it is released.