Closed SamYStudiO closed 2 years ago
I guess this func is being garbage collected since nobody keep a reference, so if you delay your permissionRequest.proceed()
then it may be null
https://github.com/permissions-dispatcher/PermissionsDispatcher/blob/c8876729dfd3cd2158d57098e56e02514792fd62/ktx/src/main/java/permissions/dispatcher/ktx/PermissionsRequesterImpl.kt#L27-L32
@SamYStudiO thx, could you give us more info for this case? in my understanding this could happen when PermissionsRequester
instance is already released from memory?
@hotchemi hello
exactly there seems to have nothing keeping a reference to requestFun
specified in my previous answer. so if you delay permissionRequest.proceed()
with a confirmation dialog for example, that function may have been garbage collected when effectively calling proceed.
@SamYStudiO thx, one thing I haven't understood is in your case PermissionsRequester
is also destroyed? If so I'm wondering we should not keep a reference to functions, otherwise, it causes the memory leak again in theory 🤔
in ktx-sample, it works as expected and do you think we can do a similar approach?
I'm not sure why ktx-sample works, i guess for this one GC hasn't been done yet, in my case
https://github.com/permissions-dispatcher/PermissionsDispatcher/blob/c8876729dfd3cd2158d57098e56e02514792fd62/ktx/src/main/java/permissions/dispatcher/ktx/KtxPermissionRequest.kt#L11
requestPermission.get()
is null if i delay it with my custom dialog implementation and wait my dialog to return a positive value
can we get an example that we can repro the issue?
The reason ktx-sample works is requestPermission
and permissionDenied
are still referenced from PermissionsRequester
AFAIK.
it's a huge projet, i may have a look to extract, but i'm pretty sure problem is requestFun
having no strong reference anywhere and so beeing destroy before we may use it
https://github.com/permissions-dispatcher/PermissionsDispatcher/blob/c8876729dfd3cd2158d57098e56e02514792fd62/ktx/src/main/java/permissions/dispatcher/ktx/PermissionsRequesterImpl.kt#L27-L32
tried https://github.com/permissions-dispatcher/PermissionsDispatcher/compare/prototype/gc_for_PermissionRequest?expand=1 but PermissionRequest worked as expected.
My advice here is to keep PermissionsRequester
alive until everything related to permission handling is finished. this is out expected use case for the API.
Hello check ktx-sample from my fork to reproduce the pb https://github.com/SamYStudiO/PermissionsDispatcher Issue is reproductible when using DialogFragment instead of AlertDialog directly If https://github.com/permissions-dispatcher/PermissionsDispatcher/blob/c8876729dfd3cd2158d57098e56e02514792fd62/ktx/src/main/java/permissions/dispatcher/ktx/KtxPermissionRequest.kt#L7 is not a weakreference pb is solved, need to make sure this is not a leak though
thx, I'll take a look
I tried your repo but could not repro the issue, unfortunately.. 🤔 could you give more environment info? I tried on Nexus5 API level 30 emulator.
This is indeed random from that project since this has a low memory impact. Calling System.gc in not enough since this is just an indication we want to run gc faster, but this will not run gc immediatly and if it's not required. I made some change to have more memory consumption by creating a huge bitmap from the app and this time this will showcase the pb each time. You may adjust bitmap size and proceed delay if required Just update or download my repo again.
thx, I suppose https://github.com/permissions-dispatcher/PermissionsDispatcher/pull/742 would resolve the issue.
ktx-1.1.2 has been released.
Overview
onLocationShowRationale
get called and i want to proceedpermissionRequest
, system permission dialog is not showing up.Environment
PermissionsDispatcher KTX
This doesn't work cause
KtxPermissionRequest.requestPermission
weakreference got lost and is nullBut this works
Any help appreciated Thx!