Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Javascript Articles
Page 529 of 534
Explain in detail about Reference-counting garbage collection in JavaScript?
Reference-counting garbage collectionThis is the simplest garbage collection algorithm.This algorithm looks out for those objects which have no references left.An object becomes eligible for garbage collection if it has no references attached to it.The garbage collection is explained in the below example.Examplevar obj = { x: { y: 2 } }; // 2 objects created. One is referenced by the other as one of its properties. // Obviously, none can be garbage-collected obj = 1; // what was the 'x' property of the ...
Read MoreHow can Detached DOM elements cause memory leak in JavaScript?
Detached Dom elementsDetached DOM elements are the elements which have been removed from the DOM but their memory is still retained because of JavaScript. This means that as long the element have a reference to any variable or an object anywhere, it does not garbage collected even after destroyed from the DOM.DOM is like an double-linked tree which means a reference to a node in the tree will halt the entire tree from garbage collection.Let's take an example of creating a DOM element in javascript. After creating the element destroy it but forget to delete the variable holding it. This ...
Read MoreHow can Forgotten timers or callbacks cause memory leaks in JavaScript?
Forgotten timers/callbacksThere are two timing events in javascript namely setTimeout() and setInterval(). The former executes a function after waiting a specified number of milliseconds, whereas the latter executes a function periodically(repeats for every certain interval of time).When any object is tied to a timer callback, it will not be released until the timeout happens. In this scenario timer resets itself and runs forever till the completion of timeout there by disallowing garbage collector to remove the memory.These timers are most frequent cause of memory leaks in javascript.ExampleIn the following example, the timer callback and its tied object(tiedObject) will not be ...
Read MoreHow to get the pixel depth and color depth of a screen in JavaScript?
Javascript window object has provided many methods to get various kinds of information regarding the browser. It has provided screen.colorDepth and screen.pixelDepth to get the color depth and pixel depth of browser screen respectively. Let's discuss them individually. Color depth The window object has provided screen.colorDepth method to return the color depth. Color depth is nothing but the number of bits used to display one color. All modern computers use 24 bit or 32 bit hardware for color resolution. Example document.getElementById("depth").innerHTML = "Screen color depth is " + screen.colorDepth; Output Screen color depth is ...
Read MoreWhat is the use of ()(parenthesis) brackets in accessing a function in JavaScript?
The ()(parenthesis) brackets play an important role in accessing a function. Accessing a function without () will return the function definition instead of the function result. If the function is accessed with () then the result can be obtained. Without () Example In the following example, the function is accessed without () so the function definition is returned instead of the result as shown in the output. function toCelsius(f) { return (5/9) * (f-32); } document.write(toCelsius); Output function toCelsius(f) { return (5/9) * (f-32); } With () Example ...
Read MoreDynamic Programming in JavaScript
Dynamic programming breaks down the problem into smaller and yet smaller possible sub-problems. These sub-problems are not solved independently. Rather, results of these smaller sub-problems are remembered and used for similar or overlapping sub-problems. Dynamic programming is used where we have problems, which can be divided into similar sub-problems so that their results can be re-used. Mostly, these algorithms are used for optimization. Before solving the in-hand sub-problem, the dynamic algorithm will try to examine the results of the previously solved sub-problems. The solutions of sub-problems are combined in order to achieve the best solution. For a problem to be ...
Read MoreHow to show if...else statement using a flowchart in JavaScript?
The if statement is the fundamental control statement that allows JavaScript to make decisions and execute statements conditionally. Let’s see how to show if…else statement using flowchart in JavaScript.
Read MoreRaise the Mobile Safari HTML5 application cache limit?
Application cache on Safari has no limit on storing data, but for mobile Safari the rues are different.The upper limit is 5MB.On mobile safari, the local storage and session storage are 5MB each. On WebSQL, a user is asked for permissions but you cannot store data any more than 50MB.With the latest iOS version, if a web app needs more then 5MB of cache storage, a user will be asked if it has permission to increase it. This is done so that the user can manage own memory space.
Read MoreDisplay video inside HTML5 canvas
You can try the following code snippet to display video inside HTML5 canvas.var canvas1 = document.getElementById('canvas'); var context = canvas1.getContext('2d'); var video = document.getElementById('video'); video.addEventListener('play', function () { var $this = this; (function loop() { if (!$this.paused && !$this.ended) { context.drawImage($this, 0, 0); setTimeout(loop, 1000 / 30); } })(); }, 0);
Read MoreEscaping/encoding single quotes in JSON encoded HTML5 data attributes
To escape single quotes, use json_encode() to echo arrays in HTML5 data attributes.printf('', htmlspecialchars(json_encode(array('html5', ...)), ENT_QUOTES, 'UTF-8'));Or you can also using built-injson_encode(array('html5', ...), JSON_HEX_APOS)
Read More