Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fn缓存严重BUG,导致内存无限增长! #108

Closed
mfeng-ya opened this issue May 17, 2024 · 3 comments
Closed

Fn缓存严重BUG,导致内存无限增长! #108

mfeng-ya opened this issue May 17, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@mfeng-ya
Copy link

mfeng-ya commented May 17, 2024

Fn内两个缓存map使用Fn实例当作key,FnName对象每次都会创建新实例,且未实现hashCode跟equals方法,导致缓存无限增长!
另外此处缓存是否可考虑限制下大小

@abel533 abel533 added the bug Something isn't working label May 17, 2024
@abel533
Copy link
Contributor

abel533 commented May 17, 2024

确认是bug,来个PR?

参考:
单元测试,FnTest添加:

  @Test
  public void testMemoryOverflow() throws InterruptedException {
    for (int i = 0; i < 100; i++) {
      System.out.println(((Fn<User, Object>) User::getUserName).toColumn());
      Assert.assertEquals(1, Fn.FN_COLUMN_MAP.size());
      Assert.assertEquals(1, Fn.FN_CLASS_FIELD_MAP.size());
    }
    for (int i = 0; i < 100; i++) {
      System.out.println(Fn.field(User.class, "userName").toColumn());
      Assert.assertEquals(2, Fn.FN_COLUMN_MAP.size());
      Assert.assertEquals(2, Fn.FN_CLASS_FIELD_MAP.size());
    }
  }

Fn.java 修改其中的 FnName,添加下面方法:

    @Override
    public boolean equals(Object o) {
      if (this == o) return true;
      if (o == null || getClass() != o.getClass()) return false;
      FnName<?, ?> fnName = (FnName<?, ?>) o;
      return column == fnName.column && Objects.equals(entityClass, fnName.entityClass) && Objects.equals(name, fnName.name);
    }

    @Override
    public int hashCode() {
      return Objects.hash(entityClass, name, column);
    }

@abel533 abel533 pinned this issue May 17, 2024
@mfeng-ya
Copy link
Author

Fn暴露的方法用到主要是获取column属性,其它方法是否多余,field跟column的映射关系是否可放到EntityTable处理,减少Fn内部实现的复杂性

@abel533
Copy link
Contributor

abel533 commented May 17, 2024

方法确实多,所有方法都有用。。这些方法是针对扩展使用的,直接使用通用方法是不需要关注的。

@abel533 abel533 unpinned this issue May 19, 2024
mfeng-ya pushed a commit to mfeng-ya/mb-provider that referenced this issue May 20, 2024
abel533 added a commit to mybatis-mapper/provider that referenced this issue May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants