Jump to content
 







Main menu
   


Navigation  



Main page
Contents
Current events
Random article
About Wikipedia
Contact us
Donate
 




Contribute  



Help
Learn to edit
Community portal
Recent changes
Upload file
 








Search  

































Create account

Log in
 









Create account
 Log in
 




Pages for logged out editors learn more  



Contributions
Talk
 



















Contents

   



(Top)
 


1 Examples  



1.1  Java  





1.2  JavaScript  







2 See also  





3 References  














Dead store






Español
Русский
Українська
 

Edit links
 









Article
Talk
 

















Read
Edit
View history
 








Tools
   


Actions  



Read
Edit
View history
 




General  



What links here
Related changes
Upload file
Special pages
Permanent link
Page information
Cite this page
Get shortened URL
Download QR code
Wikidata item
 




Print/export  



Download as PDF
Printable version
 
















Appearance
   

 






From Wikipedia, the free encyclopedia
 


Incomputer 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.[1] Some system libraries have specific functions designed to avoid such dangerous optimizations, e.g. explicit_bzeroonOpenBSD.[2]

Examples[edit]

Java[edit]

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<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>(Arrays.asList("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[edit]

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.[3]

See also[edit]

References[edit]

  1. ^ "Insecure Compiler Optimization | OWASP".
  • ^ "OpenBSD manual pages". man.openbsd.org. Retrieved 2016-05-14.
  • ^ "HTML5, and Real World Site Performance: Seventh IE9 Platform Preview Available for Developers".

  • Retrieved from "https://en.wikipedia.org/w/index.php?title=Dead_store&oldid=1209396292"

    Categories: 
    Compiler optimizations
    Software anomalies
    Programming language comparisons
    Hidden categories: 
    Use dmy dates from April 2019
    Articles with example Java code
    Articles with example JavaScript code
     



    This page was last edited on 21 February 2024, at 18:43 (UTC).

    Text is available under the Creative Commons Attribution-ShareAlike License 4.0; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.



    Privacy policy

    About Wikipedia

    Disclaimers

    Contact Wikipedia

    Code of Conduct

    Developers

    Statistics

    Cookie statement

    Mobile view



    Wikimedia Foundation
    Powered by MediaWiki