Qlik Community

Qlik Sense Integration, Extensions, & APIs

Discussion board where members can learn more about Integration, Extensions and API’s for Qlik Sense.

rbartley
Contributor III

Qlik Sense Mashup - Unloading Objects from Memory

Hi everyone,

I am having some issues with memory when loading a large number of objects that include GeoAnalytics maps. Can someone tell me how to unload an object once loaded with app.getObject()?

I have experimented with getSessionObject but without any success e.g.:

mapMY5YMY=app.getObject('mapMY5YMY','4fe5658d-f64f-4d2f-8df3-3cf3d697b882').then(function(model){

  strQID= model.id;

  });

app.destroySessionObject(strQID);

Thanks in advance.

Richard

Tags (1)
1 Solution

Accepted Solutions
bgk
New Contributor III

Re: Qlik Sense Mashup - Unloading Objects from Memory

If you use the app.visualization.get(id) instead you are able to use the visualization.close() which does just that and frees up the memory.

viz = app.visualization.get('xGhjKl');

...

viz.close()


get method ‒ Qlik Sense Developers

close method ‒ Qlik Sense Developers

14 Replies
rbartley
Contributor III

Re: Qlik Sense Mashup - Unloading Objects from Memory

I found that the way to do this is by using model.close().  However, I am using bootstrap tabs, so before doing this, I needed to identify which tab had been activated and then close all the models of the other objects.

The way I resolved this was be adding some code to the .then event of the app.getObject method.  The naming of the tab links and hrefs is important. Effectively, if the tab that is being activated is different from the sheet on which the visualization is located, then the objects on all other sheets are 'unloaded' from memory.  This seems to work well and, unsurprisingly, navigation between tabs is much quicker from a user perspective.

It would be nice for unloading to be dealt with on the Qlik Playground as I had to hunt around for this.

app.getObject(strDivID,strQID).then( function( model )

  //unload when navigate away from tab

  $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {

   var target = $(e.target).attr("href") // activated tab

   if (target!='#tab'+strHTMLTab)

   {

  model.close();

   }

  });

 

});

rbartley
Contributor III

Re: Qlik Sense Mashup - Unloading Objects from Memory

p.s. If anyone knows a better way of doing this, please let me know.

bgk
New Contributor III

Re: Qlik Sense Mashup - Unloading Objects from Memory

If you use the app.visualization.get(id) instead you are able to use the visualization.close() which does just that and frees up the memory.

viz = app.visualization.get('xGhjKl');

...

viz.close()


get method ‒ Qlik Sense Developers

close method ‒ Qlik Sense Developers

rbartley
Contributor III

Re: Qlik Sense Mashup - Unloading Objects from Memory

Hi Jonas,

Thanks for your response.  I am not familiar with the Visualization API and I have not seen any examples of it being used on the Playground or Qlik Community (perhaps I've been looking in the wrong place). They all seem to use app.getObject e.g. Getting started building mashups ‒ Qlik Sense Developers

and https://www.youtube.com/watch?v=OzzsynxIUMM

The API seems fairly limited, so I'd be interested to hear where it is better to use the Visualization app than the 'standard' getObject approach.

Employee
Employee

Re: Qlik Sense Mashup - Unloading Objects from Memory

The Visualization API can create a new object or fetch an existing one, and exposes methods for showing, destroying, and updating the object. The "Walker Dashboard" on Qlik Playground‌ uses it, and I recommend you use it exclusively over app.getObject.

rbartley
Contributor III

Re: Qlik Sense Mashup - Unloading Objects from Memory

Hi Francis,

Thanks for responding.  If i use this method, does it prevent me from using objects from the Capabilities API, such as the selection object?  Are there any limitations that I should be aware of?  Why do you recommend using it over app.getObject?

Thanks again.

Richard

Employee
Employee

Re: Qlik Sense Mashup - Unloading Objects from Memory

For the 'CurrentSelections' object, you still need to use app.getObject. For any objects you've created in the app, you can use the Visualization API.

The reason for using the Visualization API instead of the getObject method is as follows -

1. Using the Visualization API, I can both get objects that exist in the app, as well as create new objects.

2. With the getObject method, all I can do is get an object and show it immediately. With the Visualization API, there are methods for showing, closing, resizing, and setting options on an object. So I can delay showing the object if I'd like, or I can set the options on it easily (you can change dimensions and measures, colors, and pretty much anything about the object progamatically). Also, I can close it easily. And I see you've found a way to close the object using the getObject method, but it's an undocumented way of doing it, to me better to stick to documented way of doing it if one exists.

Of course, you can use both the getObject method as well as the Visualization API at the same time, they're both made available when loading the Capability APIs. But the Visualization API is capable of more than the getObject method, with the exception of grabbing the "CurrentSelections" object, so I always use the Visualization API.

rbartley
Contributor III

Re: Qlik Sense Mashup - Unloading Objects from Memory

Ok Francis, that's clearer now.  Thanks for explaining.  It would be helpful if the documentation and demos talked about these advantages more.

I'm not sure which of these responses to mark as correct since Jonas came up with the answer, but you provided additional detail.  I don't think it's possible to make both correct is it?

Employee
Employee

Re: Qlik Sense Mashup - Unloading Objects from Memory

I'd say mark Jonas' as correct and mine as helpful ;-)