dead store

Uses your system voice; voice and rate in settings.

Q3207945Snapshot

≈ 2 min read

Names in other languages

  • Españolalmacenamiento muerto
  • РусскийТупиковая запись
  • Українськатупиковий запис
  • Englishdead store

Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.

In computer programming, a dead store is a local variable that is assigned a value but is read by no following instruction. Dead stores waste processor time and memory, and may be detected through the use of static program analysis, and removed by an optimizing compiler. If the purpose of a store is intentionally to overwrite data, for example when a password is being removed from memory, dead store optimizations can cause the write not to happen, leading to a security issue. Some system libraries have specific functions designed to avoid such dangerous optimizations, e.g. explicit_bzero on OpenBSD.

In computer programming, a dead store is a local variable that is assigned a value but is read by no following instruction. Dead stores waste processor time and memory, and may be detected through the use of static program analysis, and removed by an optimizing compiler. If the purpose of a store is intentionally to overwrite data, for example when a password is being removed from memory, dead store optimizations can cause the write not to happen, leading to a security issue. Some system libraries have specific functions designed to avoid such dangerous optimizations, e.g. explicit_bzero on OpenBSD.

Examples

Java

Dead store example in Java: // DeadStoreExample.java import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class DeadStoreExample { public static void main(String[] args) { List list = new ArrayList (); // This is a Dead Store, as the ArrayList is never read. list = getList(); System.out.println(list); } private static List getList() { return new ArrayList (Arrays.asList("Hello")); } } In the above code an ArrayList 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

Dead store example in JavaScript: 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.

See also

Dead code Unreachable code

References

Text derived from https://en.wikipedia.org/w/index.php?oldid=1375585800 under CC BY-SA 4.0; modifications have been made.

Sources cited in this revision

No external citation was extracted for this revision. That is a statement about the source, not a claim that none exists.