Comment

Comment by joas_coder

public class Hello {

    public static void main(String[] args) {

        Chatter chatter = new Chatter();

        String text = "Hello " + chatter.getWord() + "!";
        System.out.println(text);
        free text; // destroy object and reclaim the memory

        free chatter; // destroy object and reclaim the memory

        // System.out.println(chatter); // use after free NEVER compiles
    }
}

// OR:

public class Hello {

    public static void main(String[] args) {

        Chatter chatter = new Chatter();
        defer free chatter;

        String text = "Hello " + chatter.getWord() + "!";
        defer free text;
        System.out.println(text);
    }
}
parent joas_coder 1 month ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton