Help with arrayList <memory leaks>

Discussion in 'Plugin Development' started by Blares, Nov 22, 2017.

Thread Status:
Not open for further replies.
  1. Offline

    Blares

    If I make a public static array list in my main class will that cause a memory leak?

    the array list is stored on a string. And I use it in many classes? Is this ok?

    Code:
    
    ArrayList<String> names = new ArrayList<>();
     
  2. Offline

    Zombie_Striker

    @Blares
    When writing plugins, there is no need for any field to be static. If an array needs to be accessed by other classes, pass the instance of the main class to that other class through its constructor.
     
  3. Offline

    MightyOne

    @Zombie_Striker isnt it basically also important fir what you would use the list?
    I mean of course if you modify it, add things, remove elements, a reliad will cause some problems. But if you would only use the get () everything would be ok?
     
  4. Offline

    Zombie_Striker

    @MightyOne
    Not really. It would work at achieving its job, but has two major flaws; bukkit does not handle static objects and that static objects show bad code structure.

    Think of it this way; imagine a city on an island and one of the buildings in that city requires access to another location far away. Which is better (i.e, which shows better planning); having a few large bridges able to handle the movement in and out of the city for all transportation, or a single bridge for each building that needs to go to specific places, even if it is just one location for one simple action?
     
  5. Offline

    MightyOne

    @Zombie_Striker I dont think that this is a good example. I mean it is totally legal to use static stuff. In the end it is the coders problem if he she loses track of which class is using what. No reason for me to blame it.
     
Thread Status:
Not open for further replies.

Share This Page