| 256 | } |
| 257 | |
| 258 | void ResourceCache::removeResource(Resource* resource) { |
| 259 | if (!resource->uniqueKey.empty()) { |
| 260 | removeUniqueKey(resource); |
| 261 | } |
| 262 | if (!resource->scratchKey.empty()) { |
| 263 | auto result = scratchKeyMap.find(resource->scratchKey); |
| 264 | if (result != scratchKeyMap.end()) { |
| 265 | auto& list = result->second; |
| 266 | list.erase(std::remove(list.begin(), list.end(), resource), list.end()); |
| 267 | if (list.empty()) { |
| 268 | scratchKeyMap.erase(resource->scratchKey); |
| 269 | } |
| 270 | } |
| 271 | } |
| 272 | totalBytes -= resource->memoryUsage(); |
| 273 | resource->release(true); |
| 274 | } |
| 275 | } // namespace tgfx |