eclipse-archived / californium.core

Californium project
86 stars 69 forks source link

Destroy CoapStack when CoapEndpoint is destroyed #49

Closed ynh-zz closed 8 years ago

ynh-zz commented 8 years ago

In the current implementation unused Endpoints and CoAPServers are not garbage collected. This due to the config observe relation between the default NetworkConfig and the layers (ReliabilityLayer and BlockwiseLayer).

Reference chain: static NetworkConfig.default > NetworkConfig > BlockwiseLayer > ObserveLayer > StackTopAdapter (inner class of) CoapStack > OutboxImpl (inner class of) CoapEndpoint > ServerMessageDeliverer > RootResource (inner class of) CoapServer Test code:

while (true) {
     CoapServer cs = new CoapServer(0);
     cs.add(new CoapResource("Test"));
     cs.start();
     Thread.sleep(10);
     cs.destroy();
     // Force GC
     System.gc();
}

Before fix:

before

After fix:

after
sophokles73 commented 8 years ago

Looks good to me :-) @mkovatsc, since it affects the area of code that you seem to be most familiar with, I think it should be you making the call and merge it to master. I think we should include this in 1.0.0, shouldn't we?

mkovatsc commented 8 years ago

Yes, Yassin is actually a student of mine and he told me about this fix. Thanks for triggering me again :) Looks also fine to me.