How are the chances for this to memoryleak Entities?

Discussion in 'Plugin Development' started by DeMaggo, Mar 27, 2013.

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

    DeMaggo

    Greetings everyone,

    I am currently developing a plugin called "MegaCreeps" for the timberman.de server and I encounter some bugs and I'm also concerned as google showed up many threads about leaking Entities.

    Entity objects are currently used as follows:

    On creation of a special entity, i wrap a class around it that uses a pointer, such as:

    Code:
        MegaPigZombie(LivingEntity e){
            this.e=e;
            setHitpoints(20);
        }
     
        MegaPigZombie(Location l){
            e=(LivingEntity) l.getWorld().spawnEntity(l,EntityType.PIG_ZOMBIE);
            setHitpoints(20);
        }
    [Safely leak-free]
    I also put the Entity as key and the wrapper as value into a static Hashmap. I create another HashMap locally while iterating over the static HashMap and put all Entities and their values into the local one in case they are .isvalid(). The previous static map then gets cleared and replaced with the new one. The wrapper objects are reliably removed.
    [/safely leak-free]

    In case of !(e.isvalid), this method is called to free the space and the entities:
    Code:
        @Override
        public boolean clear() {
            e.remove();
            e=null;
            bounty=null;
            return true;
        }
    Problem:

    Even though the entity was marked as not valid anymore and additionally removed by my call AND is no longer referenced, the entities often happen to still exist in case they were out range and did not show up anymore.

    Question:

    1) Is there a way to reliably free my objects when the entity is really getting removed?

    2) Is there some kind of memory leak concerning the entity that would prevent it to disappear in my code?
     
  2. Offline

    fireblast709

    why not just use the UUID?
     
  3. Offline

    DeMaggo

    *push*
    I found out, that in rare cases these entities dont get removed and remain invisible and invincible, attacking.
    What has to be changed?
     
  4. Offline

    lycano

    DeMaggo maybe a silly question but are you sure that those "invisible" creatues exist and its not something your client may just render as it wasnt informed about the change you do serverside?
     
  5. Offline

    DeMaggo

    They exist as they put out damage. And it's nothing about client rendering, cause these mobs are invisible, missing their model. We didn't have that problem before.

    €: Rejoining fixes this, it's clientside, happens to several people though.
     
Thread Status:
Not open for further replies.

Share This Page