Forum Xamarin.Android

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Is many shared preference a bad thing?

Xammy10Xammy10 Member ✭✭✭

I having this error:

08-29 18:01:11.640 D/Mono (15598): GC_TAR_BRIDGE bridges 0 objects 0 opaque 0 colors 0 colors-bridged 0 colors-visible 0 xref 0 cache-hit 0 cache-semihit 0 cache-miss 0 setup 0.00ms tarjan 0.00ms scc-setup 0.00ms gather-xref 0.00ms xref-setup 0.00ms cleanup 0.01ms
08-29 18:01:11.640 D/Mono (15598): GC_BRIDGE: Complete, was running for 0.13ms
08-29 18:01:11.640 D/Mono (15598): GC_MAJOR: (user request) time 172.99ms, stw 175.87ms los size: 3228K in use: 1481K
08-29 18:01:11.640 D/Mono (15598): GC_MAJOR_SWEEP: major size: 5488K in use: 4448K
08-29 18:01:11.640 I/monodroid-gc(15598): 46887 outstanding GREFs. Performing a full GC!

The only thing I add is another shared preference (I already have 4 of it) and this error start to occur.
I'm using shared preference so I can Identify my activity.

Is it bad to use too many shared preference? Even tho I save a very small amount of data.
And what is the source of this error? maybe its not shared preference.

Thanks in advance :)

Best Answer

  • Xammy10Xammy10 Member ✭✭✭
    edited August 2018 Accepted Answer

    I solve the problem, so basically, its not shared preference fault :) . You can use as many shared preference as you want. my problems is the instantiation of the activity.

    Im using:

    public SampleActivity activitySample = new SampleActivity();
    

    That's why that error is showing.

    ===========================

    But I try changing it to this:

    public SampleActivity activitySample;
    

    and on my on create:

    activitySample = new SampleActivity();
    

    I separate the variable creating and Initialization.

    I still don't get what is the difference of these two, but it solves the error when I did these :)

Answers

  • ArindamSarkarArindamSarkar Member ✭✭

    @Enohara SharePreference is for minimal data and remember data is retained even after application is killed. Please check the size of data stored and if that data is really a candidate for it. Is the data has a cross reference with other object, hence GC can't collect it?

  • Xammy10Xammy10 Member ✭✭✭

    @ArindamSarkar I'm still not sure and still searching for it, but the time I add another shared preference, that error starts to show up

  • ArindamSarkarArindamSarkar Member ✭✭

    @Enohara are you running in Debug build or in release Build, that also matters for GC

  • Xammy10Xammy10 Member ✭✭✭
    edited August 2018

    Debug build, btw, I'm using some kiosk for this project of mine :)
    And I still don't know what is the cause of that error, I tried to create an application with many shared preference but its actually working normal :)

  • Xammy10Xammy10 Member ✭✭✭
    edited August 2018 Accepted Answer

    I solve the problem, so basically, its not shared preference fault :) . You can use as many shared preference as you want. my problems is the instantiation of the activity.

    Im using:

    public SampleActivity activitySample = new SampleActivity();
    

    That's why that error is showing.

    ===========================

    But I try changing it to this:

    public SampleActivity activitySample;
    

    and on my on create:

    activitySample = new SampleActivity();
    

    I separate the variable creating and Initialization.

    I still don't get what is the difference of these two, but it solves the error when I did these :)

Sign In or Register to comment.