librime
librime copied to clipboard
add Memory::ResetUserDict() for librime-lua release user_dict before sync data
Pull request
改善 librime-lua中使用 Memory 類別時,sync user_data 異常 須要手動釋放 user_dict https://github.com/hchunhui/librime-lua/issues/335
Issue tracker
Fixes will automatically close the related issue
Fixes #
Feature
Describe feature of pull request
Unit test
- [ ] Done
Manual test
- [x] Done
Code Review
- Unit and manual test pass
- GitHub Action CI pass
- At least one contributor reviews and votes
- Can be merged clean without conflicts
- PR will be merged by rebase upstream base
Additional Info
- API 名不應該叫
Reset,聽起來像是重新初始化用戶詞典。叫Release吧。- 這個 API 似乎比較容易誤用。雖然看起來不會導致崩潰,但是會導致 Reset 之後 user_dict_ 再也不會回來。
Memory析構後自然會釋放 user_dict,所以我覺得不應該通過增加一個容易誤用的 API ad hoc 地解決問題。
問題出在 lua gc 週期,當觸發sync時
掛在 lua 中的an<Memory> 並沒有馬上釋放,
導致 user_dict sync 異常(應該是 data_sync 時 leveldb 無法開啓)