Click here to Skip to main content
15,887,027 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to convert OCX file into C# Pin
Dave Kreskowiak12-May-09 8:46
mveDave Kreskowiak12-May-09 8:46 
QuestionAnalogclock and timer Pin
Aljaz11112-May-09 7:45
Aljaz11112-May-09 7:45 
AnswerRe: Analogclock and timer Pin
nike_arh12-May-09 10:38
nike_arh12-May-09 10:38 
GeneralRe: Analogclock and timer Pin
Aljaz11112-May-09 12:07
Aljaz11112-May-09 12:07 
AnswerRe: Analogclock and timer Pin
Aljaz11112-May-09 12:44
Aljaz11112-May-09 12:44 
QuestionImages in Gridview Pin
stewy0912-May-09 6:11
stewy0912-May-09 6:11 
AnswerRe: Images in Gridview Pin
Henry Minute12-May-09 7:18
Henry Minute12-May-09 7:18 
Questionrunning out of memory, issues with GC Pin
Jon Hulatt12-May-09 5:46
Jon Hulatt12-May-09 5:46 
My app is two parts: main executable is in C#, and the core of the app is mixed native C++ with C++/CLI. The native parts use ffmpeg's libavcodec family of api's to grab select frames from a video, do some processing on them, encode them as jpeg, and then return the encoded jpeg data as a (managed) byte[] array back to the main c# app.

The app is fast, and makes a lot of allocations - there are maybe 5 frames of jpeg data returned to the main app per second, and each frame is 4.6 MB in size.

The problem is that memory usage creeps up. Short runs of the program it doesn't matter, but longer runs and I run out of memory.

The C++/CLI part of the app returns the data to the C# app simply by calling a callack funtion with a byte[] parameter.

I'm sure there are no leaks in the native code part of the app; if i comment out the line that calls the callback then the app runs forever without leaking memory.

I can therefore play with the code in the callback function - most of it is superficial and can be commented out. But the one line that seems to cause the problem is when I write the byte array to a (previously created) BinaryWriter (which is tied to a FileStream):-

// the BinaryWriter is created like this
m_outputFile = new FileStream(@"C:\filename.bin", FileMode.Create, FileAccess.Write);
m_outputWriter = new BinaryWriter(m_outputFile);

// the callback function can have everything stripped out so it looks like this
public void ReturnFrame(byte[] frameData)
{
    m_outputWriter.Write(frameData);
}


With the code like that, memory usage just keeps increasing until i run out of memory.
If I comment out the m_outputWriter.Write(frameData) line, memory usage remains in check for the entire runtime of the program. There are no other references to frameData - the caller had the only other one, which is nulled asap, as shown here.
void EncodeThread(Object^ o)
{
  // irrelevant code removed here

  array<Byte>^ jpegData = gcnew array<Byte>(Width * Height * 3);
  Marshal::Copy(IntPtr(pRgbFrame->data[0]),jpegData,0,Width * Height * 3);
  m_callback->ReturnFrame(jpegData);
  jpegData = nullptr;

  // irrelevant code removed here
}


I've tried adding a GC.Collect() after the offending line, but it doesn't make any difference.

I'm really confused as to what is going on here. The GC just doesn't seem to want to collect my garbage!

Any ideas?

Thanks

Jon

using System.Beer;

AnswerRe: running out of memory, issues with GC Pin
Luc Pattyn12-May-09 6:51
sitebuilderLuc Pattyn12-May-09 6:51 
GeneralRe: running out of memory, issues with GC Pin
Jon Hulatt12-May-09 8:06
Jon Hulatt12-May-09 8:06 
GeneralRe: running out of memory, issues with GC Pin
Luc Pattyn12-May-09 9:19
sitebuilderLuc Pattyn12-May-09 9:19 
QuestionWorking with multiple forms Pin
bwood202012-May-09 5:34
bwood202012-May-09 5:34 
AnswerRe: Working with multiple forms Pin
OriginalGriff12-May-09 5:37
mveOriginalGriff12-May-09 5:37 
GeneralRe: Working with multiple forms Pin
bwood202012-May-09 5:56
bwood202012-May-09 5:56 
AnswerRe: Working with multiple forms Pin
DaveyM6912-May-09 5:49
professionalDaveyM6912-May-09 5:49 
GeneralRe: Working with multiple forms Pin
bwood202012-May-09 6:03
bwood202012-May-09 6:03 
GeneralRe: Working with multiple forms Pin
DaveyM6912-May-09 6:20
professionalDaveyM6912-May-09 6:20 
GeneralRe: Working with multiple forms Pin
bwood202012-May-09 7:17
bwood202012-May-09 7:17 
GeneralRe: Working with multiple forms Pin
Henry Minute12-May-09 7:28
Henry Minute12-May-09 7:28 
GeneralRe: Working with multiple forms Pin
bwood202012-May-09 9:13
bwood202012-May-09 9:13 
GeneralRe: Working with multiple forms Pin
Henry Minute12-May-09 9:22
Henry Minute12-May-09 9:22 
GeneralRe: Working with multiple forms Pin
bwood202012-May-09 9:48
bwood202012-May-09 9:48 
GeneralRe: Working with multiple forms Pin
Henry Minute12-May-09 10:00
Henry Minute12-May-09 10:00 
GeneralRe: Working with multiple forms Pin
bwood202012-May-09 11:10
bwood202012-May-09 11:10 
GeneralRe: Working with multiple forms Pin
Henry Minute12-May-09 11:54
Henry Minute12-May-09 11:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.