Bug 29365 - Background images not freed when changing CSS classes
Summary: Background images not freed when changing CSS classes
Status: UNCONFIRMED
Alias: None
Product: WebKit
Classification: Unclassified
Component: CSS (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC Linux
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-09-18 02:46 PDT by Joe Edwards
Modified: 2011-01-09 17:53 PST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Joe Edwards 2009-09-18 02:46:09 PDT
If css is defined as follows:

.bg1 {
 background-image: url(img1.jpg);
} 

.bg2 {
 background-image: url(img2.jpg);
}


And then you change the background on an element using:

    document.getElementById('pagebg').className = "bg1";
or
    document.getElementById('pagebg').className = "bg2";


The "old" image reference is not freed up. (Use of cache has been disabled)

If I change the image background using 

    document.getElementById('pagebg').style.backgroundImage = 'url(img1.jpg)';
or
    document.getElementById('pagebg').style.backgroundImage = 'url(img2.jpg)';


The old image reference is correctly freed up.


I have put up pages to illustrate this behaviour:

The first use case (which caches the image) is at:
http://www.joelebeau.co.uk/testcssbg/index.htm

The 2nd use case is at:
http://www.joelebeau.co.uk/testcssbg/index2.htm


(In both pages the image loads/transitions are triggered by a key press)
Comment 1 Alexey Proskuryakov 2009-09-18 11:30:56 PDT
I'm not sure what the difference in behavior between the two linked tests is. What do you mean by "freed up"? Is this a memory leak, and if it is, how did you confirm it?
Comment 2 Joe Edwards 2009-09-18 11:47:19 PDT
Essentially i looked at the web server logs in both cases... In the first case I could see each image only being requested once.

In the 2nd case each image was re-requested before each change.

From adding debug it seems that there is still a reference (client) to the CachedImage by CSSImageValue
Comment 3 Simon Fraser (smfr) 2011-01-08 21:31:24 PST
We used to load all images referenced by matched selectors, but that was fixed by bug 49204. Does this still reproduce?
Comment 4 Alexey Proskuryakov 2011-01-09 12:23:22 PST
Simon, did you mean to reference bug 24223?
Comment 5 Simon Fraser (smfr) 2011-01-09 17:53:33 PST
(In reply to comment #4)
> Simon, did you mean to reference bug 24223?

I did, yes.