Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7646441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:12:35+00:00 2026-05-31T10:12:35+00:00

I have a page with a script that does only 2 things: change the

  • 0

I have a page with a script that does only 2 things: change the color or a background and keep a time counter. There’s a memory leak somewhere.

The JSFiddle is here

This is the script:

var TheDateToday = new Date();

var TheColorEffect = (function () {

   var TheColorArray = ['red', 'blue', 'purple'];

   return function () {

       var TheColor = Math.floor(Math.random() * 3);
       var TheOpacity = (Math.floor(Math.random() * 20) + 80) / 100;

       document.getElementById('TheText').style.color = TheColorArray[TheColor];
       document.getElementById('TheText').style.opacity = TheOpacity;

       document.getElementById('ThePanel').style.backgroundColor = TheColorArray[TheColor];
       document.getElementById('ThePanel').innerText = TheDateToday.toTimeString();
       };
   }());

var TheDateIncrement = (function () {

   return function () {
        TheDateToday.setSeconds(TheDateToday.getSeconds() + 10); };
}());

setInterval(TheDateIncrement, 10000);
setInterval(TheColorEffect, 2000);

and this is the css/html:

 #TheText{
    font-size:20px;
    font-family:Verdana;
    margin:20px 20px;
    -webkit-transition:color 2s ease;
    -moz-transition:color 2s ease;
    -o-transition:color 2s ease;
    transition:color 2s ease;}

   #ThePanel{
    height:100px;
    width:200px;
    clear:both;
    color:white;
    padding:20px 20px;
    background:red;
    -webkit-transition:background 2s ease;
    -moz-transition:background 2s ease;
    -o-transition:background 2s ease;
    transition:background 2s ease;}​


<div id="TheText">This is a test text</div>
<div id="ThePanel"></div>​

When you go to Timeline in chrome and look at the memory usage, it just goes up. And if you open several of these pages in separate tabs, the CPU can get to 90% usage.

Where’s the leak??
Thanks for your suggestions on fixing this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T10:12:36+00:00Added an answer on May 31, 2026 at 10:12 am

    I changed your code to this, found cpu and memory reduced. The function timing calls are reduced while testing the load.

    var TheColorEffect = new function () {
    
        var TheDateToday = new Date();
        var TheColorArray = ['red', 'blue', 'purple'];
        var TheColor = 0;
        var TheOpacity = 0;
    
        this.change = function () {
            TheColor = Math.floor(Math.random() * 3);
            TheOpacity = (Math.floor(Math.random() * 20) + 80) / 100;
    
            document.getElementById('TheText').style.color = TheColorArray[TheColor];
            document.getElementById('TheText').style.opacity = TheOpacity;
            document.getElementById('ThePanel').style.backgroundColor = TheColorArray[TheColor];
            document.getElementById('ThePanel').innerText = TheDateToday.toTimeString();
    
        }
    
        this.TheDateIncrement = function () {
            TheDateToday.setSeconds(TheDateToday.getSeconds() + 10);
        }
    
    };
    
    
    setInterval(TheColorEffect.TheDateIncrement, 200);
    setInterval(TheColorEffect.change, 100);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

At the minute I have a page with an AJAX script that searches a
I have a script that animates a small DIV popping up on the page.
I have a PHP script that uses CURL to fetch a remote page and
I have a script that takes a while. I'd like to display a page
I have a page that includes a dynamic js-script depending on the page I'm
I have some script in my default page that redirects users to language specific
I currently have a single jQuery script page that I include in my ScriptManager
I have a script that does an update function live. I would move it
I have a page that loads a bunch of scripts to prepopulate dropdowns and
I have a page which is largely created by DOM script, which generates a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.