Solved

JavaScript problem to reload images

Posted on 2008-10-27
9
363 Views
Last Modified: 2013-12-07
Hello,

I have made a code who reload an image in an infinite loop.

But the problem is that the numbers of elements just growing up with the time, and on my iPhone with Mobile Safari, after a moment, the reloads just stop.

I think it's because of a memory saturation.

How can I do to "free" olds images ?

Sorry for my ugly english, and thanks in advance !
<html>

	<script type="text/javascript" language="JavaScript">

	

			image1 = new Image();

			image2 = new Image();
 

	

		function reloadImage() {
 

			date = new Date();
 

			document.getElementById("texte").innerHTML = date.getTime();  

			

			image1.src = 'image.php?time=' + date.getTime();

			image2 = image1;

			document.getElementById("webcam").src = image2.src;

		}

		

		function reloadTimer() {

			setTimeout("reloadImage()", 500);

		}
 

	</script>

	

	<div id="texte" >XXXX</div>

	

	<img id="webcam" onLoad="reloadTimer()" src="image.php">

</html>

Open in new window

0
Comment
Question by:Valty
  • 5
  • 2
  • 2
9 Comments
 
LVL 12

Expert Comment

by:jazzIIIlove
ID: 22816350
Hi there;

<<I have made a code who reload an image in an infinite loop.

Why is that? Purpose?

<<How can I do to "free" olds images ?

What's that?

Best regards...
0
 

Author Comment

by:Valty
ID: 22816431
Hello jazzllllove, thanks you for your fast answer

My code can download a picture of my webcam updated regularly. A sort of streaming, but with a single image.

I do JavaScript for a short time, I wanted to know if it was necessary to "liberate" the memory of the old images, or if my problem is not here.

Regards,
0
 
LVL 12

Accepted Solution

by:
jazzIIIlove earned 250 total points
ID: 22816623
A nice tutorial related with your problem:

http://www.javascriptkit.com/javatutors/closuresleak/index.shtml
0
 

Author Comment

by:Valty
ID: 22816768
I have read the link, but I'm not really familiar with this.

Are you sure the problem I have is in relation with memory leaks ?

I would be very grateful if you could give me a sample code
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 18

Assisted Solution

by:wilq32
wilq32 earned 250 total points
ID: 22819946
I think that its more related with cache in browsers rather than memory leaks.

You can try      delete     statement, but i never tried that :(

But first of all... i dont know how this should work. You have setTimeout (so it will fire a function once) and there is no more call to reloadImages()  so after one change there will be nothing more. Just try setInterval, od use setTimeout again at the end of reloadImages function.

And as i said try before adding new Image just put  delete image1 and delete image2 maybe this will help

regards
0
 

Author Comment

by:Valty
ID: 22820611
Hello wilq32, thanks you for your answer

I have already tested with delete, but according to this post, my problem seems to be a specific mobile safari problem, because I have not this problem with other browsers :

http://groups.google.com/group/iphonewebdev/browse_thread/thread/78eeb249726f27f6?hl=en
0
 
LVL 18

Expert Comment

by:wilq32
ID: 22820729
nothing more to add :( just wait for new version of mobile browser..
0
 

Author Comment

by:Valty
ID: 22823938
Yes, I think this is the best I can do for the moment, I assign the points !
0
 

Author Closing Comment

by:Valty
ID: 31510496
Thanks !
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
SSL stands for “Secure Sockets Layer” and an SSL certificate is a critical component to keeping your website safe, secured, and compliant. Any ecommerce website must have an SSL certificate to ensure the safe handling of sensitive information like…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Shows how to create a shortcut to site-search Experts Exchange using Google in the Chrome browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch the Search Engine Menu: In chrome, via you…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now