Sunday 15 September 2013

c# - Out of memory exception after repeatedly opening file with ASP.NET web service -



c# - Out of memory exception after repeatedly opening file with ASP.NET web service -

i working on web service retrieves images , converts them pdf documents. during testing, used same several image files testing many times over. result image files have accessed cause service throw 'out of memory' exception while other images still work fine. odd thing problem persists after scheme reboot or shutdown.

foreach(string s in docids) { imageresponse img = new imageresponse(); xgraphics xgr; string[] limgs; list<string> pagenumbers = new list<string>(); seek { datarow[] foundrows = ds.tables[0].select("doc_id = " + s); (int = 0; < foundrows.length; i++) { datarow dr = foundrows[i]; pagenumbers.add(dr["page_id"].tostring()); } pdfdocument doc = new pdfdocument(); memorystream stream = new memorystream(); int count=0; string page1 = ""; (int p = 0; p < pagenumbers.count; p++) { string sdocpath = getdocpath(database, s, pagenumbers[p]); pdfpage pg = new pdfpage(); doc.addpage(pg); ximage pdfimg = ximage.fromfile(sdocpath); //the out of memory exception thrown here xgr = xgraphics.frompdfpage(pg); xgr.drawimage(pdfimg, 0, 0); pdfimg.dispose(); } doc.save(stream, false); page1 = getimagebase64(stream); ; savepdf(stream.getbuffer(), "test.pdf"); count += 1; stream.flush(); img.documenttype = getdoctypename(database, s); img.error = false; img.errormessage = ""; img.image = page1;// im_p; img.docid = s; doc.close(); }

in .net, time utilize object accesses resource file or network connection. typically implements idisposable interface. means have clean through using or calling dispose() on object.

c# asp.net asmx

No comments:

Post a Comment