20 #ifndef TESSERACT_CCUTIL_OBJECT_CACHE_H_ 21 #define TESSERACT_CCUTIL_OBJECT_CACHE_H_ 40 for (
int i = 0; i < cache_.
size(); i++) {
41 if (cache_[i].
count > 0) {
42 tprintf(
"ObjectCache(%p)::~ObjectCache(): WARNING! LEAK! object %p " 43 "still has count %d (id %s)\n",
44 this, cache_[i].
object, cache_[i].
count,
45 cache_[i].
id.
string());
47 delete cache_[i].object;
48 cache_[i].object =
nullptr;
64 for (
int i = 0; i < cache_.
size(); i++) {
65 if (
id == cache_[i].
id) {
66 retval = cache_[i].object;
67 if (cache_[i].
object !=
nullptr) {
76 ReferenceCount &rc = cache_.
back();
78 retval = rc.object = loader->
Run();
79 rc.count = (retval !=
nullptr) ? 1 : 0;
87 if (t ==
nullptr)
return false;
89 for (
int i = 0; i < cache_.
size(); i++) {
90 if (cache_[i].
object == t) {
102 for (
int i = cache_.
size() - 1; i >= 0; i--) {
103 if (cache_[i].
count <= 0) {
104 delete cache_[i].object;
112 struct ReferenceCount {
125 #endif // TESSERACT_CCUTIL_OBJECT_CACHE_H_
void DeleteUnusedObjects()
DLLSYM void tprintf(const char *format,...)
T * Get(STRING id, TessResultCallback< T *> *loader)