Question: I am having a lot of problems rewriting this SQL Query in Squeel or straight Active Record using Ruby on Rails 4.

All 3 numbers in the query need to be passed to the query before execution. The SQL Query is below.

```
SELECT "users".* 
FROM "users"  
WHERE "users"."id" 
IN (SELECT "users"."id" FROM "users"  
INNER JOIN marketing_assets ON users.id = marketing_assets.user_id 
WHERE  marketing_assets.marketing_platform_id= 3 
GROUP BY users.id HAVING COUNT(DISTINCT marketing_assets.marketing_platform_id) = 1)

```

You can find out more detail about how it is being used at [Error when trying to chain class method in controller in Ruby on Rails](https://stackoverflow.com/questions/21505042/error-when-trying-to-chain-class-method-in-controller-in-ruby-on-rails)

Answer: 
Use [WeakReference](http://docs.oracle.com/javase/7/docs/api/java/lang/ref/WeakReference.html)s.

In B and C, make your references to A like this:

```
public class B {
    private final WeakReference<A> myA;

    public B (A aToUse) {
        myA = new WeakReference<A>(aToUse);
    }

    private void doSomethingWithMyA() {
        A aToUse = myA.get();  // This returns null when the instance has been GC'd
    }        
}

```

Now, if the instance to A that you're deleting is the only instance of A that isn't a `WeakReference`, then that instance of A becomes eligible for garbage collection. Once it is garbage collected your `WeakReference`s will return `null`;
No, If i am not wrong , You want that You want that after deleting Class A, Class Band C Should to Run assigning null to the Instance of A used, 
You Can not do that, Basically when you use a class say Class A in another class say Class B , the Class Loader for the Class A, if it is found then JVM proceeds to another steps, But if you have Deleted that class , the Class Loader will not be able to find that , and will throws exception , Class Not Found Exception, or something Like that,