Skip to content

Commit a002797

Browse files
authored
A temporary fix (#254)
1 parent 1d053e0 commit a002797

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

mlx/backend/metal/device.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,16 @@ MTL::Library* load_library(
108108
}
109109
}
110110

111+
struct PoolHolder {
112+
PoolHolder() {
113+
p = NS::AutoreleasePool::alloc()->init();
114+
}
115+
~PoolHolder() {
116+
p->release();
117+
}
118+
NS::AutoreleasePool* p;
119+
};
120+
111121
} // namespace
112122

113123
Device::Device()
@@ -125,6 +135,12 @@ Device::~Device() {
125135
for (auto& l : library_map_) {
126136
l.second->release();
127137
}
138+
for (auto& b : buffer_map_) {
139+
b.second.second->release();
140+
}
141+
for (auto& e : encoder_map_) {
142+
e.second->release();
143+
}
128144
device_->release();
129145
pool_->release();
130146
}
@@ -282,9 +298,8 @@ Device& device(mlx::core::Device) {
282298
}
283299

284300
NS::AutoreleasePool*& thread_autorelease_pool() {
285-
static thread_local NS::AutoreleasePool* p =
286-
NS::AutoreleasePool::alloc()->init();
287-
return p;
301+
static thread_local PoolHolder pool{};
302+
return pool.p;
288303
}
289304

290305
void new_stream(Stream stream) {

0 commit comments

Comments
 (0)