Qlik Community

Qlik Sense Integration, Extensions, & APIs

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

rbartley
Valued Contributor

In interactive Mashup is it better to call app.getObject for all visualizations when loading page or when needed?

Hello everyone,

I have developed a number of mashups and a common requirement is to hide/show visualizations based on selections and button clicks.  For efficient design is it better to call app.getObject for all visualizations when the page loads or call it as and when the event is triggered?

Thanks in advance,

Richard

1 Solution

Accepted Solutions
Employee
Employee

Re: In interactive Mashup is it better to call app.getObject for all visualizations when loading page or when needed?

Yes, every getObject call will instantiate the model. So if you are building a single page app for example you'd want to destroy any objects you put in your view when navigating away from it. You might not see the actual visualization on the page but it's still there in the background receiving data and listening for events.

6 Replies
Employee
Employee

Re: In interactive Mashup is it better to call app.getObject for all visualizations when loading page or when needed?

Generally when the event is triggered, otherwise you have objects which are consuming resources in the background but aren't on the page.

Also make sure you call close on any returned models that aren't in use anymore or your app will starting leaking memory very fast if you don't dispose resources you aren't using anymore.

rbartley
Valued Contributor

Re: In interactive Mashup is it better to call app.getObject for all visualizations when loading page or when needed?

Thanks Alex.  When you say "Also make sure you call close on any returned models that aren't in use anymore", could you you mind be more explicit, please?  Which method(s) should I call?  A code example/extract would be helpful.

Thanks in advance.

Employee
Employee

Re: In interactive Mashup is it better to call app.getObject for all visualizations when loading page or when needed?

app.getObject().then(function(model) {

  model.close()

})

rbartley
Valued Contributor

Re: In interactive Mashup is it better to call app.getObject for all visualizations when loading page or when needed?

As far as I am aware, the only time I explicitly return the model is when exporting the data.  So, I assume that I would need to close after exporting.  Are there any other cases when the model is implicitly returned or when I might also need to close the model?

Employee
Employee

Re: In interactive Mashup is it better to call app.getObject for all visualizations when loading page or when needed?

Yes, every getObject call will instantiate the model. So if you are building a single page app for example you'd want to destroy any objects you put in your view when navigating away from it. You might not see the actual visualization on the page but it's still there in the background receiving data and listening for events.

Luminary
Luminary

Re: In interactive Mashup is it better to call app.getObject for all visualizations when loading page or when needed?

Hi Alex,

How do we unlink these visualisations when not visible?

Currently I am doing:

function getQSObjects(page){

        $("#" + page).find("div.QS").each(function() {

            var qsid = $(this).data("qsid")

            var htmlid = $(this).attr('id');

console.log('getObject',htmlid,qsid)

app.getObject(htmlid,qsid).then(function(model){

model.close();

});

   });

app.getObject('QSCALENDAR','Rppjy').then(function(model){

model.close();

});;

};

function closeQSObjects(page){

  $("#" + page).find("div.QS").each(function() {

            var qsid = $(this).data("qsid")

            var htmlid = $(this).attr('id');

console.log('destroyObject',htmlid,qsid)

app.destroySessionObject(qsid);

});

But I am not sure I the destroySessionObject works.

};

Kind Regards,

Community Browser