in the following ckt, both caps are having different charges, so while charge transfer some charge is dissipated through resistor. how to calculate it.
Your solution looks long winded.
1. Calculate the voltages in steady state after the switch has been closed. It's just a charge balance problem and doesn't depend on R.
2. Calculate stored energies in initial and final state. The difference is is the dissipated energy.
You can think like this:
Tha placement of the switch can be changed, placing it between a C and the R;
Looking between the two terminals, the series of the two C's is completely equivalent to (indistinguishable from) a single C of value Ceq (0.83... F) initially charged at Vs=V1+V2 (6 V), whose energy is Ceq*Vs^2/2.
In the final condition, all this energy is dissipated.
One more comment:
The rest of the energy in the C's (once steady state is reached) can not be extracted without accessing the node between them.
Regards