I'm working on a Producer-consumer problem with an unbounded consumer. The producer can put as many tasks into the processing queue as it wants. When the queue is empty the consumer will block the thread.
while true {
do {
guard let job = try self.queue.dequeue() else { return }
job.perform()
} catch {
print(error)
}
}
Normally I would put everything in the loop in an autorelease pool, however, it's not available on Linux. It seems as though ARC
is never releasing the objects in the loop. How should I go about controlling memory usage?
I don't believe memory spikes due to autorelease pools should be a thing on Linux. It's possible that something else could be holding onto a reference to one of your objects, though. Try setting a breakpoint in the middle of the loop, then click on "Debug Memory Graph" in the debugger to see what objects have references to the objects that are piling up. This can help determine the cause of objects that stick around longer than they ought to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With