synchronized void register(@NotNull T object, int sizeKb) {
    unregister(object);
    myNotPaintedCache.put(object, sizeKb);
    myTotalSize += sizeKb;

    // trim the cache
    while (myNotPaintedCache.size() > 1 /* don't remove just registered object */ && myTotalSize > myCacheSizeLimitKb) {
      T toRemove = myNotPaintedCache.keySet().iterator().next();
      destroy(toRemove);
      assert !myNotPaintedCache.containsKey(toRemove); // 'destroy' is supposed to call 'unregister'
    }
    while (!myPaintedCache.isEmpty() && myTotalSize > myCacheSizeLimitKb) {
      T toRemove = myPaintedCache.keySet().iterator().next();
      destroy(toRemove);
      assert !myPaintedCache.containsKey(toRemove); // 'destroy' is supposed to call 'unregister'
    }
  }
synchronized void register(@NotNull T object, int sizeKb)