Domanda

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!

È stato utile?

Soluzione

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.
}

Altri suggerimenti

I answer under the odd assumption that you have a good reason to believe that the code is still useful even though it is dead.

Store the value false in some obfuscated form that the compiler can't understand. Then, conditionally branch to that code using your obfuscated value. The compiler will not know it is dead, so it will not be removed.

I'll use a file for my example, but it is probably not the most efficient way. Say your code that the compiler thinks is dead code was in a function called myCode(). Assume that fin is reading from a file that only contains false followed by EOF

if(Boolean.parseBoolean(fin.next()))
    myCode();
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top