Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Worked around iOS mobile Safari browser bug which leaks memory… #365

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/galleria.js
Original file line number Diff line number Diff line change
Expand Up @@ -6157,11 +6157,18 @@ Galleria.Picture.prototype = {
*/

preload: function( src ) {
$( new Image() ).load((function(src, cache) {
return function() {
cache[ src ] = src;
};
}( src, this.cache ))).attr( 'src', src );
// Create a new Image; register a callback for onload
// that adds an entry in the Galleria.Picture cache
// indicating that src is already loaded; then set
// the 'src' attribute to actually start loading.
$( new Image() ).load(function() {
// Add to cache since loading of src has completed
Galleria.Picture.prototype.cache[ src ] = 1;
// Clear out the 'src' attribute when done to work around a mobile Safari
// bug that results in a memory leak if an Image object's 'src' is
// left referencing an image.
this.src = '';
}).attr( 'src', src );
},

/**
Expand Down Expand Up @@ -6314,6 +6321,9 @@ Galleria.Picture.prototype = {
};
}( this, callback, src ));

// http://stackoverflow.com/a/3993689/5299483 - clear out 'src' attribute
// to free mobile Safari memory
$container.find('img').attr('src', '');
// remove any previous images
$container.find( 'iframe,img' ).remove();

Expand Down