Search code examples
javaandroiddead-code

Dead code in Java/Android


is there a way to tell the compiler in Java or Android to not remove some statements in code -which are intended to clean up variables after use to prevent any data remnant in ram-?? would creating a dummy method solve this issue??

these statements basically set the variables to their type-based initial values..

Thanks in advance!


Solution

  • The code that you describe is not dead code. Dead code is code that will never execute. Here is an example:

    private int secretSchmarr;
    
    public boolean blammo()
    {
        boolean returnValue;
    
        secretSchmarr = calculateSecretValue();
    
        returnValue = useSecretValue(secretSchmarr);
    
        secretSchmarr = 99; // this is not dead code.
    
        return returnValue;
    
        secretSchmarr = 98; // This is dead code because it can never execute.
    }