librime icon indicating copy to clipboard operation
librime copied to clipboard

add Memory::ResetUserDict() for librime-lua release user_dict before sync data

Open shewer opened this issue 1 year ago • 1 comments

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

  1. Unit and manual test pass
  2. GitHub Action CI pass
  3. At least one contributor reviews and votes
  4. Can be merged clean without conflicts
  5. PR will be merged by rebase upstream base

Additional Info

shewer avatar Jun 20 '24 11:06 shewer

  1. API 名不應該叫 Reset,聽起來像是重新初始化用戶詞典。叫 Release 吧。
  2. 這個 API 似乎比較容易誤用。雖然看起來不會導致崩潰,但是會導致 Reset 之後 user_dict_ 再也不會回來。

Memory 析構後自然會釋放 user_dict,所以我覺得不應該通過增加一個容易誤用的 API ad hoc 地解決問題。

問題出在 lua gc 週期,當觸發sync時
掛在 lua 中的an<Memory> 並沒有馬上釋放, 導致 user_dict sync 異常(應該是 data_sync 時 leveldb 無法開啓)

image

shewer avatar Jun 21 '24 01:06 shewer