Opened 9 years ago

Closed 15 months ago

#1323 closed defect (rejected)

The ItemImage property leads to high memory consumption

Reported by: abeham Owned by: architects
Priority: medium Milestone:
Component: Core Version: 3.3.2
Keywords: Cc:

Description

The image obtained from the VS2008ImageLibrary resource manager is created anew every time the property is called. This leads on the one hand to somewhat higher memory consumption (even though this is just a small bitmap it seems to have quite an impact), but on the other hand also to leaked memory as this bitmap is not disposed anywhere.

The discussed solution so far is to remove the virtual declaration from the ItemImage property and introduce in Item a protected static Bitmap itemImage that can be set in the static initializer of a derived class defining an own icon. The property just returns this variable.

Change History (8)

comment:1 Changed 9 years ago by gkronber

I dislike the idea of static initializers for this. Can't we just have a property in Item that caches the bitmap, calling a protected virtual method CreateImage that can be overridden in sub-classes. On all subsequent calls the cached image instance is returned.

Item:
  private [static] Bitmap itemImage;
  public Bitmap ItemImage {
    [lock(locker)]
    if (itemImage==null) {
       itemImage = CreateItemImage();
    }
    return itemImage;
  }

  protected virtal Bitmap CreateItemImage() {
    object obj = ResourceManager.GetObject("Class", resourceCulture);
    return ((System.Drawing.Bitmap)(obj));
  }

If we want to have one Bitmap per type instead of one Bitmap per Item instance we can still make the itemImage field static, however, we probably also need to make the ItemImage getter thread safe.

Last edited 9 years ago by gkronber (previous) (diff)

comment:2 Changed 9 years ago by swagner

  • Owner changed from swagner to abeham
  • Status changed from new to assigned

comment:3 Changed 9 years ago by swagner

  • Milestone changed from HeuristicLab 3.3.3 to HeuristicLab x.x.x

comment:4 Changed 8 years ago by abeham

  • Priority changed from high to medium

comment:5 Changed 7 years ago by gkronber

This ticket is not resolved even after #1651 which introduced static image properties, as the Bitmap is still created via the ResourceManager each time the static getter is called.

comment:6 Changed 19 months ago by abeham

  • Owner changed from abeham to architects

I assume we can just delete this

comment:7 Changed 19 months ago by gkronber

Fine by me.

comment:8 Changed 15 months ago by jkarder

  • Milestone HeuristicLab 3.3.x Backlog deleted
  • Resolution set to rejected
  • Status changed from assigned to closed
Note: See TracTickets for help on using tickets.