If I have object A, which calls DAO object B to perform some database update – Once B's function completes it calls a call back function in A (A.finishProcess()) does this create memory issues? I mean does B then remain in memory until A completes? or is B still removed with GC?
I ask this as I’m considering using call backs instead of returning a “result” object or code from B.
In short, is it better design (and memory usage) wise to “return” an object of results rather than using a callback to a calling object?
PS: Please ignore specific’s ie, it doesn’t mention AsycnTask, its a contrived situation to get my question across 🙂
Cheers for any help
It is all about references. As long as you don’t store/keep any (strong) references around (i.e. proper deregistration, clearing references once the object is no longer in use, etc), you don’t have to worry as the object will properly be handled by GC.