问题标签 [weakhashmap]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
java - GC 不会从弱哈希图中删除对象
我有一个测试应用程序,其中包含一个存储地图的类和一个调用该类方法的按钮:
该按钮执行此操作:
因此,带有地图的主类仍然存在,但我放入它的对象是在单独的方法中创建的,因为它是一个WeakHashMap
我认为从方法退出后fillWeakHashMap
,地图中的键/对象将被 GC 清除。
我打开 VisualVM->VisualGC 并单击 Monitor->PerformGC 10 次,旧空间几乎已满,这意味着 GC 没有清除这些对象。那么我做错了什么?
java - 使用 hashmap 和 weakhasmap 进行性能/内存优化
我有一个关于hashmap和weakhashmap的问题。在我的应用程序中,我每次都会从数据库中获取10万条记录并将其放入地图中。在我对第一组记录进行一些操作后,我将获取接下来的 10 万条记录。
在这种情况下,哪种地图实现是合适的?有没有更好的数据结构来保存如此庞大的数据?
提前致谢。
java - 为什么 WeakHashMap 在 GC 后持有强引用值?
WeakHashMap 中的关键对象变得弱可达。并且 map 应该在 GC 之后删除条目。但是对值对象的强引用仍然存在。为什么?
使用番石榴弱键映射观察到相同的行为。
预期输出:
但我得到输出:
代码:
升级版:
我尝试在 jСonsole 和 jcmd 中执行 GC,但输出没有改变。
java - 是否在方法中使用 WeakHashMap?
我有一个每 5 分钟调用一次的 @Scheduled 方法。
批处理进行了大量计算,大约需要 2-15 分钟才能完成(如果批处理已经在运行,则有一个标志阻止批处理运行)。
我使用很多Map
s 来缓存计算的结果。我可以这样恢复。一个主要的 Map 将包含累积结果,以及一些 Map/List into submethod for internal calculus。
该批次可能需要大约 3-6 Gigs 才能运行。要分析大量数据。
我认为当代码退出方法时,我在方法中使用的 Map/List 将有资格获得 GC,对吗?
我应该在我的方法中使用WeakHashMap
or还是在退出方法之前WeakReference
调用?Map.clear();
如果可能的话,我想减少内存使用量,不要在批处理结束时等待 GC 进行清理。
批处理完成后,内存将减少到 500megs-1G max。
spring - spring security,如何使用户的所有会话过期
我必须解决以下场景,在 Spring Security3.2.5-RELEASE
中,Spring Core 4.1.2-RELEASE
应用程序在 Wildfly 8.1 上运行 Java 1.7。
- 用户“鲍勃”登录
- 和管理员删除“鲍勃”
- 如果“bob”注销,他将无法再次登录,但他当前的会话仍处于活动状态。
我想把“鲍勃”踢出去
/li>
java - WeakHashMap or HashMap?
So I have a chain of objects that reference each other from ORM / Hibernate
- Continent
- has many countries
- has many states
- has many cities
- has many cityparts
- Country
- has one Country
- has many states
- has many cities
- has many cityparts
- State
- has one Continent
- has one Country
- has many cities
- has many cityparts
- City
- has one Continent
- has one Country
- has one State
- has many cityparts
- City part
- has one Continent
- has one Country
- has one State
- has one City
For some methods i need to be able to do some quick lookups for identifying keys.
So for that I currently have in all the objects that have Many to be able to do quick lookups of the Id's of the object in memory without having to fire off a gazillion database queries in the lifetime of the execution thread
But what i'm worried about is cyclic references being held and the objects never getting cleared by garbage collection because they all reference eachother through the ORM relations and they all have private maps pointing to eachohter
Now I have read about WeakHashMap that it will clear the references if there are no more strong references.
The question is Is it adviceable to use WeakHashMap in my situation or am I enough served by Hashmap and this setup and cyclic references will not impair my memory management.
java - 为什么垃圾收集器不销毁任何对象作为 WeakHashMap 中没有任何引用的值?
在下面的示例中,如果垃圾收集器用作weakHashMap 中的键,则垃圾收集器正在销毁一个无用(引用较少)的对象,这没关系.. 但是如果有任何无用的对象作为值,那么垃圾收集器为什么不销毁该对象..
临时等级:-
输出
根据我的输出应该是: -
java - WeakHashMap 按身份散列?
我不明白,为什么WeakHashMap
用它们来散列键hashCode()
并用 来标识equals()
?
通过这个类的约定,它可以用来将任何实例绑定到任何其他实例。在我看来,这意味着按身份进行哈希和比较。
文档中的事件有一个关于混淆用法的注释,例如String
:
此类将非常适用于其 equals 方法不基于对象标识的关键对象,例如 String 实例。然而,使用这种可重新创建的键对象,自动删除键已被丢弃的 WeakHashMap 条目可能会令人困惑。
那么,在某些集合库中,这个类是否有任何实现,它是由身份散列的?
android - WeakHashMap 在观察者模式中没有按预期工作
我正在尝试使用 WeakHashMap 在 Android 中实现观察者模式。这里代码。
问题是然后设备旋转我希望weakhashmap观察者没有自动删除,并且在创建视图方法中添加了新的观察者。因此,在第一次旋转之后,观察者包含 2 个元素,在下一次旋转之后 - 3 等等,尽管我认为它只会是 1。怎么了?
java - 垃圾收集器使用 2 个 WeakHashMaps
我有缓存,用 WeakHashMap 实现,如下所示:
我有一个 City 类的实例:
我现在将此实例添加到我的地图中,如下所示:
根据 WeakHashMap jvm 实现,如果 key 没有对其的强引用,则将其从地图中删除(在其空闲时间)。
因此,如果程序中不再使用我的对象“c”,它将从“对象”映射中删除。
到目前为止,一切都很好。
但是如果我有两张地图会怎样?
在这种情况下,GC 会收集对象“c”吗?