weak-references

Are lapsed listeners preventable in javascript?

ぃ、小莉子 提交于 2019-12-12 11:27:01
问题 My question is really "Is the lapsed listener problem preventable in javascript?" but apparently the word "problem" causes a problem. The wikipedia page says the lapsed listener problem can be solved by the subject holding weak references to the observers. I've implemented that before in Java and it works nicely, and I thought I'd implement it in Javascript, but now I don't see how. Does javascript even have weak references? I see there are WeakSet and WeakMap which have "Weak" in their names

C#: Notification before WeakReference is collected?

删除回忆录丶 提交于 2019-12-12 09:36:00
问题 In C#/.NET, is there any way to get a notification before the object pointed to by a weak reference is destructed? Basically, I want to allow an object to be collected, but do something right before the object is destroyed, without modifying code to add destructors (since I won't know exactly what types of objects will be sued with my code). Thanks, Robert 回答1: .Net 4.0 has the solution you need: ConditionalWeakTable. Here is a short program that demonstrates the idea. (discussed here as well

Is there a way to FORCE weak and/or soft referenced objects to be GC'd in Java?

无人久伴 提交于 2019-12-12 08:22:33
问题 Here's my use case. We are trying to narrow down a potential memory leak in an application, and we are using a memory analysis tool to snapshot the heap so we can look for object instances and references. (In case it helps, we're using YourKit.) This application makes extensive use of dynamic and CGLIB proxies, which end up storing tons of references to classes and classloaders in WeakHashMaps. After our test case runs, we are expecting all hard references to object X and its classloader to

One Liner: WeakReference-to-a-Lambda Event Handler

核能气质少年 提交于 2019-12-12 07:49:17
问题 Can you see downsides to this one-liner other than the fact that multiple uses of it would violate the DRY principle? It seems straightforward but the fact that I haven't seen others propose it makes me wonder if there's a downside to it. This bit of code creates a WeakReference to a method and then registers an event handler that invokes the reference's target. SomeEvent += (sender, e) => ((Action)(new WeakReference((Action)ProcessEvent)).Target)(); Thanks, Ben 回答1: I don't think that

Why do they check WeakReference for null?

China☆狼群 提交于 2019-12-12 01:09:16
问题 Here is the blog post on android developers on how download images asynchronously: http://android-developers.blogspot.de/2010/07/multithreading-for-performance.html The code snippet from it: class BitmapDownloaderTask extends AsyncTask<String, Void, Bitmap> { private String url; private final WeakReference<ImageView> imageViewReference; public BitmapDownloaderTask(ImageView imageView) { imageViewReference = new WeakReference<ImageView>(imageView); } @Override // Actual download method, run in

In Objective C, When is weak object released under ARC?

北战南征 提交于 2019-12-11 21:08:45
问题 Since the reference count becoming 0 will cause the object being released. I am curious when is a weak object released since the count is always 0, when I declare a weak one, do I need to worry about it will be released half way? For example NSObject ClassA @property (weak) NSString stringA; - init() { ... stringA = @"this is a weak string"; ... } - doSomething() { // When I call this function later, // is there any chance at this point stringA has been released? NSLog(stringA); } 回答1: You

How can I enforce single ownership with weak_ptr? (Or, how to subclass shared_ptr and override dtor)

落爺英雄遲暮 提交于 2019-12-11 18:36:32
问题 So, I've done (a small amount) of reading and am aware that unique_ptr in combination with raw pointers is the pattern to use when modeling unique ownership. However, I really like the simple and clear concept of using a weak_ptr to check if a value is valid, and then discard the shared_ptr after using it, and this keeps everyone happy (at a slight reference counting performance cost). My particular problem right now is in creating an expressive and flexible system for tracking multitouch

WeakMultiton: ensuring there's only one object for a specific database row

大憨熊 提交于 2019-12-11 10:36:37
问题 In my application I need to ensure that for an entity representing a data row in a database I have at most one java object representing it. Ensuring that they are equals() is not enough, since I could get caught by coherency problems. So basically I need a multiton; moreover, I need not to keep this object in memory when it is not necessary, so I will be using weak references. I have devised this solution: package com.example; public class DbEntity { // a DbEntity holds a strong reference to

Weak reference to closure in Swift

♀尐吖头ヾ 提交于 2019-12-11 10:20:11
问题 I have the following code to create an observable property for data binding. It's in the works so I'm not sure what the final implementation is going to be and I'm still pretty new to Swift. class Observable<T> { typealias Observer = T -> Void var value: T { didSet { for observer in self.observers { observer?(self.value) } } } var observers: [Observer?] = [] init(_ val: T) { self.value = val } } I would like to keep weak references to the Observer closures. I don't want to rely on the client

Assembler .weak directive does only work with Cross Compile GCC

非 Y 不嫁゛ 提交于 2019-12-11 08:05:54
问题 I have a program which I compile with 2 different compilers: GCC 3.4.4 Cross Compiler for PowerPC GCC 4.8.1 MinGW Compiler In the program I am using the assembler directive .weak . The documentation says: Makes a symbol with weak binding globally visible to the linker. So I am going like this: __asm__(".weak " "foo" "\n.set " "foo" "," "dummy_foo" "\n"); To cleare foo weak and give it an alias to dummy_foo . This code works fine under GCC 3.4.4 when I cross compile für PowerPC but it doesn't