I have the following method that is called when the delete button is pressed in an IOS keyboard app extension:
func delete()
{
dispatch_async(dispatch_get_main_queue(),
{
for _ in 1..<50
{
(self.textDocumentProxy as UIKeyInput).deleteBackward()
}
print("Deletion End")
})
}
However, each time this method is called my keyboard's memory usage goes up by 1-2mb and it does not come back down. This quickly results in a crash.
I am not allocating or de-allocating any objects in this thread, so I am not sure why there is a massive memory leak.
UPDATE:
I changed dispatch_get_main_queue()
to a static variable:
let mainqueue = dispatch_get_main_queue()
and used mainqueue
inplace of dispatch_get_main_queue
but this did not do anything.
UPDATE 2:
I added a variable called tempProxy
that is created each time delete is called:
let tempProxy = (self.textDocumentProxy as UIKeyInput)
Then in dispatch_async
I used this:
tempProxy.deleteBackward()
I did this because I heard that having references to self
could cause memory retention.
UPDATE 3:
I changed:
(self.textDocumentProxy as UIKeyInput).deleteBackward()
to a print()
statement.
The memory usage was now a lot less. However, I was confused as to why the memory was still not being released.