By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,722 Members | 1,277 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,722 IT Pros & Developers. It's quick & easy.

Releasing the resource retrieved by Assembly.GetManifestResourceStream()

P: n/a

I'm developing an application that periodically reads embedded assembly
resources. The resources are text-based, and are about 3-7KB in size,
and the application accesses them by calling the
Assembly.GetManifestResourceStream() method.

During a long period of execution, I've noticed that the memory usage
of the application increases; specifically, it appears that the
System.IO.__UnmanagedMemoryStream returned by
GetManifestResourceStream() is never collected, even when the owning
thread leaves the scope in which it is defined.

I used SciTech's memory profiler to track down this issue and was able
to reproduce it with the appended code.

Does someone know if there is a way to force the release of the
resources used by System.IO.__UnmanagedMemoryStream? Perhaps I am not
using Assembly.GetManifestResourceStream() as it is intended.

Any ideas or suggestions are appreciated!
Sample Program:

// Wrapper for Assembly.GetManifestResourceStream().
class ResourceReader {

public ResourceReader( string strResourceFile ) {
cstrResourceFile = strResourceFile;

public string GetText() {
Stream oResourceStream = null;
TextReader oReader = null;

try {
oResourceStream =
Assembly.GetExecutingAssembly().GetManifestResourc eStream(
cstrResourceFile );
oReader = new StreamReader( oResourceStream );
return oReader.ReadToEnd();
catch( Exception ) {
return String.Empty;
finally {
if( oResourceStream != null ) {

if( oReader != null ) {

private string cstrResourceFile;

// Program entry point.
class TestHarness {

static void Main(string[] args) {
string data = null;
ResourceReader oReader = new ResourceReader(
"ConsoleApplication1.TextFile1.txt" );
int n = 0;

while( true ) {
data = oReader.GetText();
System.Threading.Thread.Sleep( 3000 );

if( n % 250 == 0 ) {


Steve Guidi

Nov 22 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.