weak-references

How can I lower the weak ref processing time during GC?

依然范特西╮ 提交于 2019-12-03 06:21:02
Currently I am facing the problem that my application is showing long GC times sporadically, but all these are only caused by weak reference processing. So the thread stopped time is always close to the weak ref processing time. All other GC cycles are 0.0001 sec to 0.200 sec. From the gc.log (reformatted): 10388.186: [GC[YG occupancy: 206547 K (306688 K)]10388.186: [Rescan (parallel) , 0.1095860 secs]10388.295: [weak refs processing, 2.0799570 secs] [1 CMS-remark: 2973838K(3853568K)] 3180386K(4160256K), 2.1899230 secs] [Times: user=2.51 sys=0.00, real=2.18 secs] Total time for which

Can't make weak reference to closure in Swift

会有一股神秘感。 提交于 2019-12-03 05:44:32
Update: I tried writing it without making it weak, and there doesn't seem to be a leak. So maybe the question is no longer necessary. In Objective-C ARC, when you want to have a closure be able to use itself inside of the closure, the block cannot capture a strong reference to itself, or it will be a retain cycle, so instead you can make the closure capture a weak reference to itself, like so: // This is a simplified example, but there are real uses of recursive closures int (^fib)(int); __block __weak int (^weak_fib)(int); weak_fib = fib = ^(int n) { if (n < 2) return n; else return weak_fib

Creating a weak subscription to an IObservable

一笑奈何 提交于 2019-12-03 04:55:54
问题 What I want to do is ensure that if the only reference to my observer is the observable, it get's garbage collected and stops receiving messages. Say I have a control with a list box on it called Messages and this code behind: //Short lived display of messages (only while the user's viewing incoming messages) public partial class MessageDisplay : UserControl { public MessageDisplay() { InitializeComponent(); MySource.IncomingMessages.Subscribe(m => Messages.Items.Add(m)); } } Which is

Indexable weak ordered set in Python

自闭症网瘾萝莉.ら 提交于 2019-12-03 04:34:56
问题 I was wondering if there is an easy way to build an indexable weak ordered set in Python. I tried to build one myself. Here's what I came up with: """ An indexable, ordered set of objects, which are held by weak reference. """ from nose.tools import * import blist import weakref class WeakOrderedSet(blist.weaksortedset): """ A blist.weaksortedset whose key is the insertion order. """ def __init__(self, iterable=()): self.insertion_order = weakref.WeakKeyDictionary() # value_type to int self

Android: the GC doesn't respect SoftReferences?

跟風遠走 提交于 2019-12-03 02:54:16
It seams that Dalvik's garbage collector doesn't respect SoftReferences and removes them as soon as possible, just like WeakReferences. I'm not 100% sure yet, but despite the fact that there is still ~3MB of free memory my SoftReferences get cleared after I see "GC freed bla-bla-bla bytes" in LogCat. Also, I saw a comment by Mark Murphy here : Except that it doesn't work on Android, at least in the 1.5 timeframe. I have no idea if the GC SoftReference bugs have been fixed. SoftReferences get GC'd too soon with this bug. Is it true? Are SoftReferences not respected? How to workaround this?

JVM G1GC's mixed gc not collecting much old regions

感情迁移 提交于 2019-12-03 02:07:20
My server is using 1.8.0_92 on CentOS 6.7, GC param is '-Xms16g -Xmx16g -XX:+UseG1GC'. So the default InitiatingHeapOccupancyPercent is 45, G1HeapWastePercent is 5 and G1MixedGCLiveThresholdPercent is 85. My server's mixed GC starts from 7.2GB, but it clean less and less, finally old gen keeps larger than 7.2GB, so it's always try to do concurrent mark. Finally all heap are exhausted and full GC occurred. After full GC, old gen used is under 500MB. I'm curious why my mixed GC can't collect more, looks like live data is not so much... I have tried printing g1 related info, and found many

Is self captured within a nested function

淺唱寂寞╮ 提交于 2019-12-03 01:43:45
With closures I usually append [weak self] onto my capture list and then do a null check on self: func myInstanceMethod() { let myClosure = { [weak self] (result : Bool) in if let this = self { this.anotherInstanceMethod() } } functionExpectingClosure(myClosure) } How do I perform the null check on self if I'm using a nested function in lieu of a closure (or is the check even necessary...or is it even good practice to use a nested function like this) i.e. func myInstanceMethod() { func nestedFunction(result : Bool) { anotherInstanceMethod() } functionExpectingClosure(nestedFunction) } rintaro

When to use weak references in Python?

白昼怎懂夜的黑 提交于 2019-12-03 01:39:58
问题 Can anyone explain usage of weak references? The documentation doesn't explain it precisely, it just says that the GC can destroy the object linked to via a weak reference at any time. Then what's the point of having an object that can disappear at any time? What if I need to use it right after it disappeared? Can you please explain them with some good examples? Thanks 回答1: The typical use for weak references is if A has a reference to B and B has a reference to A. Without a proper cycle

“Weak reference”: down to earth explanation needed

荒凉一梦 提交于 2019-12-03 00:16:57
Can someone provide an explanation of a weak reference in Delphi? I noticed that the concept is often mentioned in some library/framework source code I scrutinize. I'm in a limbo and want to have a clear cut understanding of it. Instances that reference each other by interface references keep each other alive in a reference count based interface implementation. A weak reference is used to break the "keep each other alive" bear hug. This is done by declaring one reference as a pure pointer to circumvent the reference counting mechanism. IFriend = Interface(IInterface) end; TFriend = class

weakref list in python

爱⌒轻易说出口 提交于 2019-12-02 22:44:21
I'm in need of a list of weak references that deletes items when they die. Currently the only way I have of doing this is to keep flushing the list (removing dead references manually). I'm aware there's a WeakKeyDictionary and a WeakValueDictionary, but I'm really after a WeakList, is there a way of doing this? Here's an example: import weakref class A(object): def __init__(self): pass class B(object): def __init__(self): self._references = [] def addReference(self, obj): self._references.append(weakref.ref(obj)) def flush(self): toRemove = [] for ref in self._references: if ref() is None: