jcassee / angular-hypermedia

Hypermedia REST API client for AngularJS applications
MIT License
38 stars 5 forks source link

HalResources not cleared in ResourceContext #45

Closed rivabu closed 6 years ago

rivabu commented 6 years ago

Hi,

I'm solving memory issues in our application. One of the issues is the ever growing size of the ResourceContext.

After creating a ResourceContext, and clicking through our application the number of resources is growing rapidly. The number of resources is only increasing and never decreasing. Is there a way to cleanup unused resources?

I also tried to put the resources in different ResourceContexts, but that didn't solve my issues either.

In the screenshot, there is 1 ResourceContext with 1216 resources.

screen shot 2018-01-22 at 11 16

See the attached screenshot for details.

jcassee commented 6 years ago

Yes, this is by design and the whole reason d'etre of the ResourceContext object: resource scope management. The idea is to scope a context to a "unit of work" that loads a set of related resources. I would advise creating a context in the resolve function of the view. (Might be a parent view used by a set of related subviews, of course.)

Does that help?

rivabu commented 6 years ago

Thanks, but it doesn't solve our issue.

When we use different ResourceContexts, none of these contexts are cleared. The total number of resources in these contexts isn't lower compared to one ResourceContext. Do you know why the resources are not removed? I suppose that not-used resources should be removed from the context automatically?

jcassee commented 6 years ago

Do you keep references to either the context or its resources? The assumption is that, say, when the user navigates away from a view that had a context defined in its resolve function, no other parts of the application keeps references to that context or its resources.

rivabu commented 6 years ago

Thanks, yes, that's how we did it. But there's still something in our application that has a reference to these resources. We are still searching for the root cause, but the angular-hypermedia modules works as expected. Thanks for your fast response.

jcassee commented 6 years ago

Tracking references in JavaScript can be a bit of a pain. :-( I hope you work it out. I'll close this ticket. Feel free to reopen if you discover angular-hypermedia is not doing what it is supposed to do after all.