From e8c47ac7d2dc3ef0d550e6fe00d1b55ccf4e2aa2 Mon Sep 17 00:00:00 2001 From: "binbin.hou" Date: Fri, 26 Apr 2024 17:42:14 +0800 Subject: [PATCH] release branch 0.16.0 --- CHANGE_LOG.md | 6 ++++++ README.md | 19 +++++++++++++++--- pom.xml | 2 +- release.bat | 4 ++-- .../word/api/ISensitiveWordDestroy.java | 11 ++++++++++ .../houbb/sensitive/word/api/IWordData.java | 2 +- .../sensitive/word/bs/SensitiveWordBs.java | 7 ++++++- .../word/support/data/WordDataHashMap.java | 7 +++++++ .../word/support/data/WordDataTree.java | 6 ++++++ .../word/support/data/WordDataTreeNode.java | 11 +++++++++- .../word/bs/SensitiveWordBsDestroyTest.java | 20 +++++++++++++++++++ 11 files changed, 86 insertions(+), 9 deletions(-) create mode 100644 src/main/java/com/github/houbb/sensitive/word/api/ISensitiveWordDestroy.java create mode 100644 src/test/java/com/github/houbb/sensitive/word/bs/SensitiveWordBsDestroyTest.java diff --git a/CHANGE_LOG.md b/CHANGE_LOG.md index bc9b39d..4fe3a3b 100644 --- a/CHANGE_LOG.md +++ b/CHANGE_LOG.md @@ -298,3 +298,9 @@ | 序号 | 变更类型 | 说明 | 时间 | 备注 | |:---|:-----|---------------------|:-------------------|:-------------------------------------------------| | 1 | F | 调整默认文件名称,避免和其他框架重合。 | 2024-4-23 21:02:25 | https://github.com/houbb/sensitive-word/issues/54 | + +# release_0.16.0 + +| 序号 | 变更类型 | 说明 | 时间 | 备注 | +|:---|:-----|----------------------|:-------------------|:-------------------------------------------------| +| 1 | F | 支持资源的释放,如 andriod 场景 | 2024-4-26 21:02:25 | https://github.com/houbb/sensitive-word/issues/53 | diff --git a/README.md b/README.md index 8fb871e..2301c10 100644 --- a/README.md +++ b/README.md @@ -52,9 +52,9 @@ [CHANGE_LOG.md](https://github.com/houbb/sensitive-word/blob/master/CHANGE_LOG.md) -V0.15.0: +V0.16.0: -- [x] 修复 [#54](https://github.com/houbb/sensitive-word/issues/54) +- [x] 支持内存释放 [#53](https://github.com/houbb/sensitive-word/issues/53) ## 更多资料 @@ -86,7 +86,7 @@ V0.15.0: com.github.houbb sensitive-word - 0.15.0 + 0.16.0 ``` @@ -450,6 +450,19 @@ Assert.assertTrue(wordBs.contains(text)); | 13 | charIgnore | 忽略的字符 | none | | 14 | wordResultCondition | 针对匹配的敏感词额外加工,比如可以限制英文单词必须全匹配 | 恒为真 | +## 内存的释放 + +有时候我们需要释放内存,可以如下: + +> [关于内存回收问题](https://github.com/houbb/sensitive-word/issues/53) + +```java +SensitiveWordBs wordBs = SensitiveWordBs.newInstance() + .init(); +// 后续因为一些原因移除了对应信息,希望释放内存。 +wordBs.destroy(); +``` + # wordResultCondition-针对匹配词进一步判断 ## 说明 diff --git a/pom.xml b/pom.xml index 652dcad..e08f8a8 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.github.houbb sensitive-word - 0.15.0 + 0.16.0 diff --git a/release.bat b/release.bat index 642d2ed..98f802c 100644 --- a/release.bat +++ b/release.bat @@ -10,9 +10,9 @@ ECHO "============================= RELEASE START..." :: 版本号信息(需要手动指定) :::: 旧版本名称 -SET version=0.15.0 +SET version=0.16.0 :::: 新版本名称 -SET newVersion=0.16.0 +SET newVersion=0.17.0 :::: 组织名称 SET groupName=com.github.houbb :::: 项目名称 diff --git a/src/main/java/com/github/houbb/sensitive/word/api/ISensitiveWordDestroy.java b/src/main/java/com/github/houbb/sensitive/word/api/ISensitiveWordDestroy.java new file mode 100644 index 0000000..ca81210 --- /dev/null +++ b/src/main/java/com/github/houbb/sensitive/word/api/ISensitiveWordDestroy.java @@ -0,0 +1,11 @@ +package com.github.houbb.sensitive.word.api; + +public interface ISensitiveWordDestroy { + + /** + * 资源的销毁 + * @since 0.16.0 + */ + void destroy(); + +} diff --git a/src/main/java/com/github/houbb/sensitive/word/api/IWordData.java b/src/main/java/com/github/houbb/sensitive/word/api/IWordData.java index 0a4f90c..24cfab8 100644 --- a/src/main/java/com/github/houbb/sensitive/word/api/IWordData.java +++ b/src/main/java/com/github/houbb/sensitive/word/api/IWordData.java @@ -11,7 +11,7 @@ import java.util.Collection; * @author binbin.hou * @since 0.0.1 */ -public interface IWordData { +public interface IWordData extends ISensitiveWordDestroy { /** diff --git a/src/main/java/com/github/houbb/sensitive/word/bs/SensitiveWordBs.java b/src/main/java/com/github/houbb/sensitive/word/bs/SensitiveWordBs.java index 0cb702a..c8638cc 100644 --- a/src/main/java/com/github/houbb/sensitive/word/bs/SensitiveWordBs.java +++ b/src/main/java/com/github/houbb/sensitive/word/bs/SensitiveWordBs.java @@ -32,7 +32,7 @@ import java.util.Set; * @author binbin.hou * @since 0.0.1 */ -public class SensitiveWordBs { +public class SensitiveWordBs implements ISensitiveWordDestroy { /** * 私有化构造器 @@ -573,6 +573,11 @@ public class SensitiveWordBs { return wordTag.getTag(word); } + @Override + public void destroy() { + + } + //------------------------------------------------------------------------------------ 公开方法 END } diff --git a/src/main/java/com/github/houbb/sensitive/word/support/data/WordDataHashMap.java b/src/main/java/com/github/houbb/sensitive/word/support/data/WordDataHashMap.java index 0840522..696f5b0 100644 --- a/src/main/java/com/github/houbb/sensitive/word/support/data/WordDataHashMap.java +++ b/src/main/java/com/github/houbb/sensitive/word/support/data/WordDataHashMap.java @@ -183,4 +183,11 @@ public class WordDataHashMap extends AbstractWordData { return currentMap; } + @Override + public synchronized void destroy() { + if(innerWordMap != null) { + innerWordMap.clear(); + } + } + } diff --git a/src/main/java/com/github/houbb/sensitive/word/support/data/WordDataTree.java b/src/main/java/com/github/houbb/sensitive/word/support/data/WordDataTree.java index 0cc6da0..53c67a9 100644 --- a/src/main/java/com/github/houbb/sensitive/word/support/data/WordDataTree.java +++ b/src/main/java/com/github/houbb/sensitive/word/support/data/WordDataTree.java @@ -117,4 +117,10 @@ public class WordDataTree implements IWordData { return currentMap; } + @Override + public void destroy() { + if(this.root != null) { + this.root.destroy(); + } + } } diff --git a/src/main/java/com/github/houbb/sensitive/word/support/data/WordDataTreeNode.java b/src/main/java/com/github/houbb/sensitive/word/support/data/WordDataTreeNode.java index 350adce..95ee43c 100644 --- a/src/main/java/com/github/houbb/sensitive/word/support/data/WordDataTreeNode.java +++ b/src/main/java/com/github/houbb/sensitive/word/support/data/WordDataTreeNode.java @@ -1,5 +1,7 @@ package com.github.houbb.sensitive.word.support.data; +import com.github.houbb.sensitive.word.api.ISensitiveWordDestroy; + import java.util.HashMap; import java.util.Map; @@ -8,7 +10,7 @@ import java.util.Map; * * @since 0.7.0 */ -public class WordDataTreeNode { +public class WordDataTreeNode implements ISensitiveWordDestroy { /** * 关键词结束标识 @@ -46,4 +48,11 @@ public class WordDataTreeNode { return this; } + @Override + public void destroy() { + if(subNodeMap != null) { + subNodeMap.clear(); + } + } + } diff --git a/src/test/java/com/github/houbb/sensitive/word/bs/SensitiveWordBsDestroyTest.java b/src/test/java/com/github/houbb/sensitive/word/bs/SensitiveWordBsDestroyTest.java new file mode 100644 index 0000000..d117830 --- /dev/null +++ b/src/test/java/com/github/houbb/sensitive/word/bs/SensitiveWordBsDestroyTest.java @@ -0,0 +1,20 @@ +package com.github.houbb.sensitive.word.bs; + +import org.junit.Test; + +/** + * 资源的销毁 + * + * @since 0.16.0 + */ +public class SensitiveWordBsDestroyTest { + + @Test + public void destroyTest() { + SensitiveWordBs wordBs = SensitiveWordBs.newInstance() + .init(); + // 后续因为一些原因移除了对应信息,希望释放内存。 + wordBs.destroy(); + } + +}