MemorizingTrustManager icon indicating copy to clipboard operation
MemorizingTrustManager copied to clipboard

MTM should not hold a reference to possible ephemeral Android components (Activity, Service)

Open Flowdalic opened this issue 10 years ago • 3 comments

as it prevents those components from getting gc'ed.

The type of the master field should be changed to Application.

Flowdalic avatar Sep 07 '14 10:09 Flowdalic

You don't always have a global Application context. It requires you to use a global application object. It is perfectly valid for MTM to hold on to an ephemeral handle meaning it is less likely to get picked up by the collector. The documentation should say that the handle should either be firm (application/service) or extremely close to the socket (activity) and not from an easily collectable (view,fragment) context.

indrora avatar Sep 07 '14 13:09 indrora

You don't always have a global Application context.

Care to elaborate? When do you not have an application context, when an Activity or Service instance exists?

It requires you to use a global application object.

No, we just fetch the Application context form e.g. the Activity via Activity.getApplication()

It is perfectly valid for MTM to hold on to an ephemeral handle meaning it is less likely to get picked up by the collector.

I'm confused, why do you want to prevent the garbage collector from cleaning up the unused Activity instance?

Flowdalic avatar Sep 07 '14 13:09 Flowdalic

The Activity/Service dependency is a legacy, it needs to be replaced. In that context, I need to address the creation of notifications vs. direct Activity launch, it looks like the mechanism behind was changed in one of the last Android releases.

ge0rg avatar Sep 30 '14 18:09 ge0rg