Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report on
Developer Community or GitHub with
your current version information, steps to reproduce, and relevant error
messages or log files if you are hitting an issue that looks similar to
this resolved bug and you do not yet see a matching new report.
Created attachment 7559 [details]
Test case (Xamarin.Mac)
Garbage collection interferes with Objective-C messaging sending or maybe native handles?
In this test case, many recursive message sends are made by an `NSUrlProtocol` subclass and an `NSUrlConnectionDelegate` subclass. `GC.Collect()` is called once during each recursive call. After several of these recursive calls, the `Url` property of the `NSUrlRequest` method parameter sometimes returns an `NSUrl` with `Handle == IntPtr.Zero`. Additionally, two _consecutive_ calls to the `Url` property sometimes return _different_ results.
## Steps to reproduce
1. Build and run the attached Xamarin.Mac test case in either the Debug or Release configuration.
(Note: currently the Debug configuration has bundling + linking enabled. That just speeds things up a bit. You can disable them both if you like.)
2. Open a new window in the app.
After a little while the console output shows a message similar to this:
> Stopped after 75 requests: url1.Scheme = , url2.Scheme = file
> Stopped after 110 requests: url1.Scheme = , url2.Scheme = file
> Stopped after 117 requests: url1.Scheme = , url2.Scheme = file
## Expected result
The console output never shows any "Stopped" messages. Instead the app should continue to make calls to `CanInitWithRequest()` _indefinitely_ as described on .
You can produce this expected result by removing the calls to `GC.Collect()` and `GC.WaitForPendingFinalizers()` from `CustomUrlProtocol.CanInitWithRequest()`. Removing just the call to `GC.WaitForPendingFinalizers()` does not change the result.
## Version information
Mono 3.6.0 ((no/f540f8a)
Also tested on Mono 3.6.1 (2111224)
Xcode 5.1 (5084), build 5B130a
OS X 10.9.4
Created attachment 7560 [details]
Just on the small chance that a corresponding Objective-C sample might come in handy, here's a quick, fairly close translation of the C# sample.
The behavior in this bug might also be the same issue described in :
"I'm getting some intermittent loading issues [with a custom NSUrlProtocol] where sometimes a WebView will load but other times it will not."
This is a Xamarin.Mac bug specific to its binding engine.
One additional observation that might be helpful:
I can also produce the "expected result" if I leave the explicit garbage collection calls unchanged, and instead wrap the two `NSUrl` variables `url1` and `url2` in `using` statements so that they are disposed at the end of each call to `CanInitWithRequest()`.
On an unrelated note, the call to `Request.MutableCopy()` is not required to produce the problem. If you like, you can remove that line, and then replace:
> connection = new NSUrlConnection (newRequest, connectionDelegate);
> connection = new NSUrlConnection (Request, connectionDelegate);
I have checked this issue and able to reproduce this reported behavior. To reproduce this issue I have followed the steps provided in Bug description.
Steps I followed:
1. Open attached sample application in XS.
2. Build and run the application
3. Open a new window in the app
4. After a little while the console output shows a message:
Stopped after 319 requests: url1.Scheme = , url2.Scheme = file
Stopped after 355 requests: url1.Scheme = , url2.Scheme = file
Stopped after 359 requests: url1.Scheme = , url2.Scheme = file
Stopped after 361 requests: url1.Scheme = , url2.Scheme = file
Stopped after 362 requests: url1.Scheme = , url2.Scheme = file
Application Output: https://gist.github.com/anonymous/72d414eac49d00071340
=== Xamarin Studio ===
Version 5.5.3 (build 6)
Installation UUID: 011d70a5-dede-428b-ab04-ef451c2e539d
Mono 3.10.0 ((detached/e204655)
GTK+ 2.24.23 (Raleigh theme)
Package version: 310000023
=== Xamarin.Android ===
Version: 4.18.1 (Business Edition)
Android SDK: /Users/MM/Desktop/android-sdk-macosx
Supported Android versions:
2.1 (API level 7)
2.2 (API level 8)
2.3 (API level 10)
3.1 (API level 12)
3.2 (API level 13)
4.0 (API level 14)
4.0.3 (API level 15)
4.1 (API level 16)
4.2 (API level 17)
4.3 (API level 18)
4.4 (API level 19)
4.4.87 (API level 20)
4.5 (API level 21)
Java SDK: /usr
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)
=== Apple Developer Tools ===
Xcode 6.0.1 (6528)
=== Xamarin.iOS ===
Version: 184.108.40.206 (Business Edition)
Build date: 2014-10-22 15:09:12-0400
=== Xamarin.Mac ===
Version: 220.127.116.11 (Business Edition)
=== Build Information ===
Release ID: 505030006
Git revision: fbe3e9453daf6a3bb9a9709ed22bec35f7c9056b
Build date: 2014-10-23 13:08:38-04
Xamarin addins: e44add2b39de4dd57c0742bb2e620dfad84c64c6
=== Operating System ===
Mac OS X 10.9.5
Darwin MacMini.local 13.4.0 Darwin Kernel Version 13.4.0
Sun Aug 17 19:50:11 PDT 2014
This bug has been open for a long time, so I ported the example to Xamarin.Mac Unified and I can't reproduce it.
Sorry for the delay, but it appears to have been fixed sometime after 2014