Bug 6085 - Unify Java.Lang.Object and System.Object
Summary: Unify Java.Lang.Object and System.Object
Status: ASSIGNED
Alias: None
Product: Android
Classification: Xamarin
Component: General (show other bugs)
Version: 4.2.x
Hardware: PC Mac OS
: Low enhancement
Target Milestone: master
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2012-07-11 16:26 UTC by Jonathan Pryor
Modified: 2016-09-02 21:11 UTC (History)
4 users (show)

See Also:
Tags: XATriaged
Is this bug a regression?: ---
Last known good build:


Attachments

Description Jonathan Pryor 2012-07-11 16:26:48 UTC
Context: http://mono-for-android.1047100.n5.nabble.com/Type-systems-java-lang-Object-and-System-Object-tp5710827.html

Scenario: Many people want to use the Android.Views.View.Tag property to tie the UI to a "model" object, and the "model" object shouldn't be tied to the implementation framework. That is, instead of the current:

    public Java.Lang.Object Tag {get; set;}

they want:

    public object Tag {get; set;}

Most/all method return values and parameters could make use of similar treatment: use System.Object instead of Java.Lang.Object.

The reason this previously wasn't done was because it was felt that it would be beneficial making gref creation explicit, so that the gref count can be more easily reasoned about. In practice, this is bunk, as we provide a variety of methods which will happily implicitly wrap non-Java.Lang.Object types into an internal Java.Lang.Object wrapper:

    var items = new JavaList<object> ();
    items.Add (new List<int> {1, 2, 3, 4}); // implicitly wraps!

The proper solution for tracking grefs is twofold:

1. Provide better tooling for tracking them. gref logging is a start:

    http://docs.xamarin.com/android/advanced_topics/diagnostics

2. (Long-term) Rework the GC system so that grefs aren't as widely used, making gref lifetime less problematic.

NOTE: the s/Java.Lang.Object/object/g change described here would be a (large!) API break. It will not happen before 5.0 or later (some major version change). The 4.x series WILL maintain backward compatibility.

Note You need to log in before you can comment on or make changes to this bug.