The Etiquette of using multiple Ti.Network.createHTTPClient clients

You must Login before you can answer or comment on any questions.

Hey Folks,

I am using multiple xhr clients to fetch images. I Don't have any idea on how to deallocate xhr objects from memory. I am declaring xhr objects in a loop. Will asigning xhr to null in the end of xhr.onload do the trick? do i also need to remove the event listeners -> xhr.onload and ->xhr.onerror on each object? using Android 2.3.3 with ti sdk 2.0.1GA2

Thanks

1 Answer

Sounds like a bad idea. Why don't you just get your application server to generate a single JSON file with pointers to all those images? In this way you can loop over a single xhr client and get everything. (of course this depends on what exactly you are doing).

but roughly speaking, going through a loop of xhr's ... sounds nasty :-)

Just share your code to get a feeling of what you are doing and see how to improve this.

G.

— answered 11 months ago by George Georgiou
answer permalink
3 Comments
  • well actually i am receiving a single json file which has stored links of all the images which i have to load. But if i assign the image link to the "url" property of ImageView in a loop the UI is locked, By locked UI i mean my UI cant receive any click, tap e.t.c events until all the urls of images are loaded! So thats y i am making different xhr requests for each image and in the onload on each xhr object i am creating the respective imageview with image. In this way my app behaves like a threaded app with each thread for each image.

    — commented 11 months ago by Aadil Farooq

  • @George, Thanks for the answer. If thers a better solution than this please guide. I hope I can learn from different people here.

    Thanks

    — commented 11 months ago by Aadil Farooq

  • Maybe you can load only the images that you need ? (i.e. if the screen can hold up to 5 images, then load 5, and if one scrolls down, you can load the next 5's)

    The problem with tapping is that it cannot work because the full loading event has not been completed....

    — commented 11 months ago by George Georgiou

Your Answer

Think you can help? Login to answer this question!