Dead store

Dead store

In Computer programming, if we assign a value to a local variable, but the value is not read by any subsequent instruction, then it is referred to as a Dead Store. Dead Stores are wasteful of processor time and memory, and may be detected through the use of Static Analysis.

Java example of a Dead Store:

// DeadStoreExample.java
import java.util.ArrayList;
import java.util.List;
 
public class DeadStoreExample {
 public static void main(String[] args) {
   List<String> list = new ArrayList<String>(); // This is a Dead Store, as the ArrayList is never read. 
   list = getList();
   System.out.println(list)
 }
 
 private static List<String> getList() {
   return new ArrayList<String>("hello");
 }
}

In the above code an ArrayList<String> object was instantiated but never used. Instead, in the next line the variable which references it is set to point to a different object. The ArrayList which was created when list was declared will now need to be de-allocated, for instance by a Garbage Collector.

JavaScript example of a Dead Store:

function func(a, b) {
    var x;
    var i = 300;
    while (i--) {
        x = a + b; // dead store
    }
}

"The code in the loop repeatedly overwrites the same variable, so it can be reduced to only one call."[1]

  1. ^ "HTML5, and Real World Site Performance: Seventh IE9 Platform Preview Available for Developers". http://blogs.msdn.com/b/ie/archive/2010/11/17/html5-and-real-world-site-performance-seventh-ie9-platform-preview-available-for-developers.aspx. 

Wikimedia Foundation. 2010.

Игры ⚽ Поможем написать реферат

Look at other dictionaries:

  • Dead code elimination — (englisch für Entfernung von totem Code) ist ein Verfahren aus dem Bereich des Compilerbaus, das nicht verwendete Anweisungen beseitigt. Dadurch kommt es zu einem kleineren Programm mit schnellerer Ausführung. Erläuterung mit Beispielen Gegeben… …   Deutsch Wikipedia

  • Dead code elimination — In compiler theory, dead code elimination is a compiler optimization to remove code which does not affect the program results. Removing such code has two benefits: it shrinks program size, an important consideration in some contexts, and it… …   Wikipedia

  • Dead Rising 2 — North American cover Developer(s) Capcom, Blue Castle Publi …   Wikipedia

  • Dead Kennedys — From left to right: Klaus Flouride, Jello Biafra, D.H. Peligro and East Bay Ray Background information Also known as The Sharks The Creamsicles Pink Twinkies …   Wikipedia

  • Dead Head Fred — Developer(s) Vicious Cycle Software Publisher(s) Namco Bandai Games (ported versions) D3 Publisher …   Wikipedia

  • Dead Woman's Shoes (The Twilight Zone) — Dead Woman s Shoes The Twilight Zone episode Scene from Dead Woman s Shoes Episode no. Season 1 Episode 9a …   Wikipedia

  • Dead Space 2 — Developer(s) Visceral Games Publisher(s) Electronic Arts Composer(s) …   Wikipedia

  • Dead Beat (novel) — Dead Beat   Dead Beat …   Wikipedia

  • Dead Man's Walk —   …   Wikipedia

  • Dead Head Fred — Файл:Dead head fred 4e2671ae655f9.jpg Разработчик Vicious Cycle Software Издатель Namco Bandai Games (ported versions) D3 Publisher (PlayStation Portable) …   Википедия

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”