3
votes

Assume a page that shows a complex data structure (for example, an article with many details). This view will be reused from time to time by rebinding it to different articles.

Now, I noticed that the ODataModel keeps all used article entities in memory (also if they are no longer bound to any control).

This will lead to two issues:

  1. Memory consumption increases over time (if application will not be reloaded).
  2. If the application forces a refresh of the data model, all entities will be loaded (also not used).

The second issue seems to be the bigger problem. It slows down the speed of the application.

I have not found a solution for that problem. If I use refresh(true, true) it seems all data will be reloaded.

Is there an way to clean the model?

Edit

Lets say you have a list of thousands of articles. User can click on one of the articles and will navigate to a detailed screen of that article. The OData model in client side will cache this. To see it, do something like:

var oModel = this.getModel("modelName");

look with the debugger into oModel.oData.

If the user now navigates back and chooses the next article, this will be cached as well.

If user does this 1000 times, all articles are now in the model. If you trigger a oModel.refresh(true);, all these data (of 1000 articles) will be reloaded not only the one bound to the view.

Now my application is not about showing article information. It's a more complex structure with subitems. Each time user is visiting this page, more data will be cached (and re-fetched in case of a refresh call on the model).

Edit 2

The function updateBindings(bForceUpdate?) seems to help a little bit. Anyhow, the data accumulation is still there in the ODataModel class. That means: Each visited data path will stay in memory since the next reload (F5) of the full page. If someone uses such an application over a day, the data accumulates and a refresh call on the model will read all data again, if still bound to a view or not.

3
Looks like after three years still not good solution. Maybe in SAPUI5 1.52.x the new invalid method of OData would help. But I am forced to use 1.48.x at the moment :-/user3783327

3 Answers

2
votes

Try deleteCreatedEntry(oContext). Even though this is not the supposed use case for this method it might work to delete an entity from the model without triggering a backend request.

You could also try if updateBindings(bForceUpdate?) only triggers an update on actually bound entities.

1
votes

1) I do not really understand your problem here. What is it exactly that you do? OData always holds the result of your request plus a queue of changes to that request. If you create lots of entries while your application is running, of course the memory consumption will increase. If you want to revert back to the original request you can use resetChanges(). THis way the used memory should decrease again. But you lose all your changes to the model.

2) Maybe you should look into Odata filtering (http://www.odata.org/getting-started/basic-tutorial/) so that you only load the entities you really want. If you only want a part of the entity loaded then you should maybe redesign your entities to avoid a lot of overhead.

It is hard to speculate what your exact problem is.

-3
votes

Well, if you know exactly what are you doing, you can try something like this:

this.getModel("modelname").aBindings = []

Better solution would be go through the aBindings array and remove redundant bindings.