Possible memory leak / performance bug found.

I think I have found a possible memory leak / performance bug while doing some scripting.

I needed to put some extra tags in the head of the html so I created this script.

// Create array of head tags to be added
var headTags = [
    '<!-- The character set should be utf-8 -->',
    '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">',
    '<!-- Enables media queries -->',
    '<meta name="viewport" content="width=device-width">'
];
// Add the head tags to the head
results.html(results.html() + headTags.join(' '));

After using this for some time my program became slower and slower. Then I looked at the generated HTML and saw thousands of extra head tags. This script kept adding them and saving them, not reloading the default head code it seems.

I have created a workaround for this issue but I would like to see a better solution.

// Create array of head tags to be added
var headTags = [
    '<!-- The character set should be utf-8 -->',
    '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">',
    '<!-- Enables media queries -->',
    '<meta name="viewport" content="width=device-width">'
];
// Create regex to remove duplicate head tags as workaround
// For some reason if you add tags to the head they stay there forever. So when you reload the page it gets added again and again and again.
var regexFixHead = new RegExp('(' + headTags.join(' ').replace('/', '\/') + '){1,}', 'gi');
// Use workaround regex on head
results.html(results.html().replace(regexFixHead, ''));

// Add the head tags to the head
results.html(results.html() + headTags.join(' '));

Hello Sven:

That’s not a memory leak though. That is the consequence of appending a new copy of your head tags to the existing copy of the head tags, instead of just replacing the existing contents. By doing results.html() + headTags.join(’ ') , you are forcing the software to read the existing contents first, which I believe causes the problem.

Your last line should read: results.append(headTags.join(’ '));

However, please note that you can set all your meta tags directly in the UI, by right-clicking on the Web Section (Section 1 by default), going in Properties, and adding them to the Meta information here. The script, in this case, is actually unnecessary.

~Evie

Hi,

Thank you for your answer. I did not know I could just add meta tags in the designer without scripts, thanks for showing me.

Although I did try to use the append method, it didn’t seem to work. Also, I thought this was a bug because the body doesn’t work that way (reusing existing content) to my knowlede, so I thought the head would work that way too.

Anyways, thanks for the information.

Kind Regards,
Sven Slijkoord