Commit 103b5a7
[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.1 parent 634a880 commit 103b5a7
1 file changed
+1
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
30 | | - | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| |||
0 commit comments