You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Mono.Android] ResourceIdManager.UpdateIdValues called N times (#1855)
Fixes: #1544
I was able to verify that my app's `Resource.UpdateIdValues()` was
getting invoked multiple times with VS 15.7.4:
- Create a new Xamarin.Android app
- Create a new Xamarin.Android library, reference it from the app
- (Optional) call
`Android.Runtime.ResourceIdManager.UpdateIdValues()` directly
By placing a breakpoint, and/or `Log.Debug()` messages, I can verify
that my app's `Resource.UpdateIdValues()` was being called 5 times!
The issue lies in this code:
if (id_initialized)
return;
//System.Reflection code to call Resource.UpdateIdValues() in the app
id_initialized = true;
While `Resource.UpdateIdValues()` is being invoked,
`ResourceIdManager.UpdateIdValues()` is called recursively. The
`id_initialized` field will not be set until after the reflection
code has finished.
The fix is to immediately set the flag:
if (id_initialized)
return;
id_initialized = true;
//System.Reflection code to call Resource.UpdateIdValues() in the app
I was able to verify the fix in my app:
- Build the app with `xabuild`
- Re-add the `Log.Debug` message in my app's
`Resource.UpdateIdValues()`
- Deploy the app with `xabuild`
- Upon launch, I *now* only see 1 log message with `adb logcat`
The performance impact is likely:
- The reflection code would be slow in
`Android.Runtime.ResourceIdManager.UpdateIdValues()`
- In the app's `Resource.UpdateIdValues()`, mostly fields are being
read and set. It *helps* to skip this, but it shouldn't be as
slow as the reflection code.
0 commit comments