Мне нужно использовать родную библиотеку (это не мое решение). В библиотеке уже есть обертка JNI, и пример кода Android NDK работает. Но процедуры инициализации библиотеки возвращают собственные дескрипторы, и разработчику необходимо правильно их закрыть.Когда я должен освобождать собственные (Android NDK) ручки?
Теперь, есть интересный вопрос: где вызвать процедуры close_handle?
По крайней мере теоретически каждое неправильное завершение может привести к временным файлам, оставленным где-то на диске, или к утечке какого-либо другого типа.
Инициализация библиотеки занимает от 0,5 до 1 секунды и потребляет много памяти.
Activity
является контроллером (в смысле MVC), Android может убить его по своим собственным причинам, включая поворот устройства, и единственная функция, которая будет называться, - onPause()
. Таким образом, /onResume
является плохим местом для долгой ресурсоемкой операции.
(я знаю о android:configChanges="keyboardHidden|orientation"
, но я предпочел бы решение, которое не нуждается.)
Application
бы идеальным кандидатом (я считаю библиотеку, чтобы быть частью модели), но есть событие «приложение не завершено».
Service
звучит многообещающе, что родная библиотека это сервис, но я просто не понимаю, как я могу иметь желаемое поведение: ручки должны быть закрыты, когда приложение завершается.
Тайм-ауты: звучит как компромисс, но на самом деле он гарантирует, что память не будет доступна в тот момент, когда она понадобится, но станет доступна через несколько секунд.
Ровно на каких ручках вы ссылаетесь? – NuSkooler
Детали конфиденциальны («немного здоровой паранойи никому не навредит»), но библиотека использует инициализацию в N шагах, каждый шаг возвращает дескриптор. В C они непрозрачные ручки; для Java они передаются в целые числа. N шагов, потому что, по крайней мере теоретически, вы можете повторно инициализировать несколько бит. – 18446744073709551615
Вопрос был проголосован. Это странно, если это не означает, что поддержка получила аналогичный запрос :) – 18446744073709551615