473,729 Members | 2,355 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Deleting a preloaded image from memory

How can I really delete a preloaded image from memory/disk cache? Let's
say I preload an image by creating an Image object and setting its src
attribute to desired URL:

var img = new Image();
img.src = [someurl];

Then I use the image a few more times by adding it into an Array
object:

var images = new Array();
images.push(img );

I found out that just calling 'delete' on a pointer to that Image
object, doesn't free up the RAM.

delete images[0]; //RAM is not freed here!

Should I call delete on all the references to the image object? This
would be a real pain, since I have to check about 3000 lines of code
for possible references to it and make sure I 'delete' all of them...
What about the other new Image objects, that get their src attribute
set to the same url?

May 17 '06 #1
62 17824
iv********@gmai l.com wrote:
How can I really delete a preloaded image from memory/disk cache? Let's
say I preload an image by creating an Image object and setting its src
attribute to desired URL:

var img = new Image();
img.src = [someurl];
img = null;
Then I use the image a few more times by adding it into an Array
object:

var images = new Array();
images.push(img );

I found out that just calling 'delete' on a pointer to that Image
object, doesn't free up the RAM.

delete images[0]; //RAM is not freed here!
images = null;
[...]


Hope this helps,

--
Bart

May 17 '06 #2
Setting a pointer to null obviously won't delete the object pointed to
from memory, but just change the address the pointer is referencing
(from address of the object to null = 0x0000000). The object might get
deleted if the memory is managed and a garbage collector finds out
there is no more reference to the object in question. However if any
other pointer is still referencing the same object, the memory manager
will keep it in memory. That's just how it works.

The solution you gave me is not just useless, but even less effective
than the one I wrote in the question myself. Any other ideas?

May 17 '06 #3
iv********@gmai l.com wrote:
Setting a pointer to null obviously won't delete the object pointed to
from memory, but just change the address the pointer is referencing
(from address of the object to null = 0x0000000). The object might get
deleted if the memory is managed and a garbage collector finds out
there is no more reference to the object in question. However if any
other pointer is still referencing the same object, the memory manager
will keep it in memory.


I've done some investigation about this issue. My way (setting to
'null') and your way (delete method) do not seem to free up any memory
of the objects (CPU benchmarks on MSIE and FF). My conclusion is that
there is no reliable way to do what you want. There's only one JScript
function:

CollectGarbage( );

But that is (explicitly) undocumented and (explicitly) unofficial
though, and that usually has a good reason.

Some good references and quotes:

http://groups.google.com/group/comp....e35c3a102831/:

"The problem is that you don't really have a way to know when the
garbage collector will free the memory. It is a task with low priority"

http://msdn.microsoft.com/msdnmag/is.../default.aspx:

"Now, you can force the JScript garbage collector to run with the
CollectGarbage( ) method, but I don't recommend it. The whole point of
JScript having a GC is that you don't need to worry about object
lifetime. If you do worry about it then you're probably using the wrong
tool for the job!"

http://msdn.microsoft.com/msdnmag/is.../default.aspx:

"JScript was designed to provide a quick, easy way to write simple
scripts on Web pages. The fact that you're asking at all makes me think
that you're using the wrong tool for the job."

http://groups.google.com/group/micro...811edbedf33d/:

"Yes, calling CollectGarbage( ) is wrong. It's undocumented for a
reason. It won't solve any of your problems."

--
Bart

May 17 '06 #4
Yes, garbage collector is a low-priority task that should run
automatically in JavaScript, just as it does in Java, C# and other
'modern' languages. Its designed to 'ease' the memory handling. But the
more I think about my problem, the more I get the sense that it's
probably not really connected to garbage collector.

I think objects that get cached by a browser are handled on
another/higher level, than other "programmatical " objects, created by a
script. In fact we are speaking about two different kinds of memory
data - one is the data that is put in cache (image bytes, html text)
and the other is data of DOM programming objects (which make a language
'object oriented').

The programming objects are handled by a 'garbage collector' and are
freed after no pointer references them anymore. On the other side, the
cached data can still be left there (in cache) even after one closes
the browser application (that means in the 'disk cache' memory) in
order to make the rendering of the page faster next time in a short
period. The pure proof of this is that even when i close the browser
(and I see that RAM gets freed), the next time I open it and run the
same web application preloading the same images, they get 'loaded' in
an instance.

There should be (if they exist at all) some other functions not related
to garbage collector to manage the data that is cached. I know how to
explicitly make a page not being cached, by adding some special tags
into the html file. However this is not my preference, because I want
to be able to preload images when I need to, so I wonder: is there any
way to control (delete) the cached data once its cached?

May 17 '06 #5
To clarify my problem I will give an example of what I'm really trying
to achieve:

My application preloads images one after another when the user browses
a gallery, so there are always 10 images loaded in advance. These
images get shown immediately when the user reaches them, so she doesn't
have to wait.

Now when the user had already browsed over 100 of images, I would like
to delete some of them at the beginning of the 'playlist' and free the
memory so my application can run this way for hours.

How do I achieve this?

May 17 '06 #6
iv********@gmai l.com wrote:
To clarify my problem I will give an example of what I'm really trying
to achieve:

My application preloads images one after another when the user browses
a gallery, so there are always 10 images loaded in advance. These
images get shown immediately when the user reaches them, so she doesn't
have to wait.
I think you're looking for a functionality like SQL's FLUSH or Perl's
buffer disable/clean on command. I don't believe this can be controlled
on-the-fly in browsers, though there are META-instructions to control
this on page-level:

<META HTTP-EQUIV="cache-control" CONTENT="no-cache">
<META HTTP-EQUIV="expires" CONTENT="Thu, 8 May 2006 11:30:00 GMT">
(or whatever date)
<META HTTP-EQUIV="pragma" CONTENT="no-cache">
Now when the user had already browsed over 100 of images, I would like
to delete some of them at the beginning of the 'playlist' and free the
memory so my application can run this way for hours.
How do I achieve this?


The whole idea is that a browser should do all this for you, so you
don't have to worry about it (ideally). I would advocate the use of
another computer language if you need this kind of low level memory
block access.

You could develop the gallery in Macromedia Flash, end let the SWF-file
handle its own memory objects (I believe this would stand apart from
the browser's memory allocation). I'm not sure if Flash/ActionScript
could go as low as influencing RAM on-the-fly. Maybe some Flash
Newsgroup could shed a light on this.

--
Bart

May 18 '06 #7
The problem is I really need to achieve this in Firefox because I am
making an extension.

May 19 '06 #8
iv********@gmai l.com wrote:
Setting a pointer to null obviously won't delete the object pointed to
from memory,
True, except of the "pointer" term. This is ECMAScript, not C; there are
references, not pointers.

The operation marks the object referred to for garbage collection, unless
there are other references to that object.
but just change the address the pointer is referencing
(from address of the object to null = 0x0000000).


Pure speculation.
PointedEars
--
Indiana Jones: The Name of God. Jehovah.
Professor Henry Jones: But in the Latin alphabet,
"Jehovah" begins with an "I".
Indiana Jones: J-...
May 23 '06 #9
iv********@gmai l.com wrote:
The problem is I really need to achieve this in Firefox because I am
making an extension.


There is no need for preloading in the first place.
PointedEars
May 23 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2006
by: TomA | last post by:
Hi All, I have a picturebox on a form containing the photo of a person. As you advance through the records, the photo updates. Rather than storing the images in an inefficient blob field in a table, I have the separate images stored in an image directory with primary key as the filename (3476.jpg). If the image exists, I display the image. All this works fine. I have a buttons that allow for the insertion and deletion of photos. ...
3
6505
by: vunet.us | last post by:
why am i unable to insert image background into a tr or td element in IE using preloaded image object, like this: var img = new Image(); img.src = 'blah.gif'; document.getElementById('someId').style.backgroundImage = "url('"+img.src+"')"; <table><tr id='someId'><td>content</td></tr></table>
0
8761
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9281
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9200
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9142
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8148
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3238
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2163
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.