Silverlight uses XCP tmp files for Web Requests

05 Feb 2010

It would appear that the Silverlight runtime creates a file named XCP*.tmp of around 20MB within a users %temp% directory (where * can be replaced by random characters). This file would appear to be used in some way by the Silverlight runtime for web requests. If you refresh your Silverlight application then this file is cleaned up. However, if your web request is interrupted in some way then the file can be left in your %temp% directory slowly but surely eating up disk space.

This is particularly noticeable and reproducible if you are using the HttpWebRequest class to stream data (for more information on streaming data from Silverlight you can listen to my podcast and read my article in a free MSDN book). You can then reproduce the loss of connection using Fiddler (which seriously rocks and is becoming more and more useful) by right-clicking on the streaming connection and selecting "Abort Session".

[caption id="attachment_695" align="alignnone" width="529" caption="Fiddler - Abort Session"][/caption]

The best solution to resolve this that I've found is to manually invoke the garbage collector whenever you detect the connection loss.

// Manually invoke Garbage collection