C#winform资源释放问题 5C

C#在调用Aspose.Cells.dll把Excel表格生成图片时内存占用率会越来越高是什么问题?

 Workbook book = new Workbook(Application.StartupPath + @"\Config\excel.xlsx");
            Worksheet sheet = book.Worksheets[0];

            sheet.PageSetup.LeftMargin = 0;
            sheet.PageSetup.RightMargin = 0;
            sheet.PageSetup.BottomMargin = 0;
            sheet.PageSetup.TopMargin = 0;

            ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
            imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Bmp;

            imgOptions.OnePagePerSheet = true;
            imgOptions.PrintingPage = PrintingPageType.IgnoreBlank;

            SheetRender sr = new SheetRender(sheet, imgOptions);
            sr.ToImage(0, Application.StartupPath + @"\Config\Excel.bmp");

这段代码是放在timer里面定时循环执行的!

10个回答

不排除aspose有内存泄漏,用using把Workbook、SheetRender都包括进来,或者用dispose方法释放下。

qq_41222492
qq_41222492 哦哈哈哈哈
接近 2 年之前 回复
single_day
single_day 具体怎么操作呢?能说说么?
接近 2 年之前 回复

@caozhy 具体该怎么操作呢,对刚刚接触C#没多久还望指教!

不排除aspose有内存泄漏,用using把Workbook、SheetRender都包括进来,或者用dispose方法释放下

包括进来,或者用dispose方法释放下

把Workbook、SheetRender都包括进来,或者用dispose方法释放 这个可能性很大

把Workbook、SheetRender都包括进来,或者用dispose方法释放 这个可能性很大

把Workbook、SheetRender都包括进来,或者用dispose方法释放 这个可能性很大

用USING关键字包括进来

single_day
single_day 用不了,提示说“Worksheet”: using 语句中使用的类型必须可隐式转换为“System.IDisposable”
接近 2 年之前 回复

个人觉得此处应当用Task执行此处的生成图片代码,这样应该会好一点。

single_day
single_day Task不会用哦!!!!
接近 2 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
【【资源释放的问题】】
假如程序出现异常,没有继续执行后面的代码,也没能调用Dispose()方法去释放。rn那么如何保证在这种情况下,能够释放掉数据库连接对象和命令对象之类的呢?省点资源rn也就是说,不管在什么情况下,都能释放掉
资源释放问题
下面是一段ftp下载的代码,下载完后的文件依然被进程占用,我想移动这个文件,一直提示,这个文件被占用!rnrn[code=C#]rnusing System;rnusing System.Collections.Generic;rnusing System.ComponentModel;rnusing System.Data;rnusing System.Drawing;rnusing System.Linq;rnusing System.Text;rnusing System.Windows.Forms;rnusing System.Threading;rnusing System.IO;rnrnnamespace Updaternrn public partial class Form1 : Formrn rn public Form1()rn rn InitializeComponent();rn rn public static string FileName = System.Windows.Forms.Application.StartupPath + "\\System\\Sys.ini";rn public static string downpath = System.Windows.Forms.Application.StartupPath + "\\temp";rn [System.Runtime.InteropServices.DllImport("kernel32")]rn public static extern long WritePrivateProfileString(string section, string key,rn string val, string filePath);rnrn /*参数说明:section:INI文件中的段落;key:INI文件中的关键字;val:INI文件中关键字的数值;rn filePath:INI文件的完整的路径和名称。*/rnrn [System.Runtime.InteropServices.DllImport("kernel32")]rn public static extern int GetPrivateProfileString(string section, string key, string def,rn StringBuilder retVal, int size, string filePath);rnrn /*参数说明:section:INI文件中的段落名称;key:INI文件中的关键字;def:无法读取时候时候的缺省rn 数值;retVal:读取数值;size:数值的大小;filePath:INI文件的完整路径和名称。*/rnrnrn int UDTimes = 0;rn //rn private void button1_Click(object sender, EventArgs e)rn rn if (label2.Text == label4.Text)rn rn MessageBox.Show("已经是最新版本!","提示",MessageBoxButtons.OK,MessageBoxIcon.Asterisk);rn rn else rn rn progressBar1.Visible = true;rn Down();rn StringBuilder temp2 = new StringBuilder(255);rnrnrn GetPrivateProfileString("version", "NewVs", "服务器地址读取错误。", temp2, 255, FileName);rn string NewVs = temp2.ToString();rnrn WritePrivateProfileString("version", "Vs", NewVs, FileName);rn WritePrivateProfileString("version", "Flag", "1", FileName);rn if (MessageBox.Show("升级已完成,重新进入订单系统?","提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk)rn == DialogResult.OK)rn rn CopyFile(downpath , System.Windows.Forms.Application.StartupPath );rn rn rn rnrn private void Form1_Load(object sender, EventArgs e)rn rn // timer1.Enabled = true;rn StringBuilder temp2 = new StringBuilder(255);rnrn GetPrivateProfileString("version", "Vs", "服务器地址读取错误。", temp2, 255, FileName);rn string ver = temp2.ToString();rn GetPrivateProfileString("version", "NewVs", "服务器地址读取错误。", temp2, 255, FileName);rn string NewVs = temp2.ToString();rn GetPrivateProfileString("version", "Flag", "服务器地址读取错误。", temp2, 255, FileName);rn string Flag = temp2.ToString();rnrn this.label2.Text = ver;rn this.label4.Text = NewVs;rn if (label2.Text == label4.Text)rn rn timer1.Enabled = false;rn rn else rn rn timer1.Enabled = true;rn rn rnrn private void CopyFile(string StartPath, string EndPath)rn rn System.IO.File.Delete(EndPath);rnrn FileStream fs = new FileStream(StartPath, FileMode.Open);rn //定义内存缓冲区rn byte[] buffer = new byte[(int)fs.Length];rn //将文件读入到内存缓冲区中rn fs.Read(buffer, 0, buffer.Length);rn fs.Close();rnrn //定义一个文件流,用于将缓冲区中的文件流写入文件rn FileStream fs1 = new FileStream(EndPath, FileMode.Open);rn //写入文件rn fs1.Write(buffer, 0, buffer.Length);rn fs1.Close();rn rnrn private void timer1_Tick(object sender, EventArgs e)rn rn StringBuilder temp2 = new StringBuilder(255);rnrn GetPrivateProfileString("version", "Vs", "服务器地址读取错误。", temp2, 255, FileName);rn string ver = temp2.ToString();rn GetPrivateProfileString("version", "NewVs", "服务器地址读取错误。", temp2, 255, FileName);rn string NewVs = temp2.ToString();rn GetPrivateProfileString("version", "Flag", "服务器地址读取错误。", temp2, 255, FileName);rn string Flag = temp2.ToString();rnrn label2.Text = ver.ToString();rn label4.Text = NewVs.ToString();rn UDTimes = UDTimes + 1;rnrn if (label2.Text == label4.Text)rn rn timer1.Enabled = false;rn rn else rn rn progressBar1.Visible = true;rnrn Down();rn rn StringBuilder temp = new StringBuilder(255);rnrnrn GetPrivateProfileString("version", "NewVs", "服务器地址读取错误。", temp2, 255, FileName);rn string NewVs1 = temp2.ToString();rnrn WritePrivateProfileString("version", "Vs", NewVs1, FileName);rn WritePrivateProfileString("version", "Flag", "1", FileName);rnrn rn rn //down方法:rn private void Down() rn rn FtpDown ftp = new FtpDown();rn rn string last = "";rnrn string[] name = new string[] ;rnrn name = ftp.GetFileList();rnrn for (int i = 0; i < name.Length; i++)rn rn if (name[i].ToString().StartsWith("Client_CT"))rn rn string FileName1 = name[i].ToString();rnrn if (System.IO.File.Exists(downpath + "\\" + name[i].ToString()))rn rn System.IO.File.Delete(downpath + "\\" + name[i].ToString());rn rn ftp.Download(downpath, FileName1,progressBar1, out last);rnrn rn rn rn ftp.CloseFtp();rn rn //ftp.Dispose();rnrn //ftp.Close();rn rn rn Thread.Sleep(1000);rn rn rnrn private void timer2_Tick(object sender, EventArgs e)rn rn //if (System.IO.File.Exists(downpath + "\\Client_CT.exe")) rn //rnrn // timer2.Enabled = false;rn rn rn // if (MessageBox.Show("升级已完成,重新进入订单系统?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk)rn // == DialogResult.OK)rn // rn // CopyFile(downpath + "\\Client_CT", System.Windows.Forms.Application.StartupPath + "\\Client_CT");rn // rn // progressBar1.Visible = false;rn //rn rnrnrnrn rnrnrnrn[/code]
资源释放的问题
SqlConnection 在Close连接后,需要再调用Dispose吗?rnSqlCommand和SqlDataAdapter呢?rnrn如何判断哪些资源是托管的,哪些是非托管的。
资源释放问题?
我在窗体的OnClose里Action:=cafree;在OnDestroy里form1:=nilrn为什么老是当窗体关闭时弹出内存出错的提示.哪位高手帮忙指点一下
资源释放的问题?
我做了一个用户控件A,在这个对象里new 了几个其它用户控件b1,c1。rn问:我需要释放几个其它用户控件b1,c1吗?怎么释放,在什么事件里释放?
资源释放
前言Activity整生命周期于onCreate()与onDestroy()调用间。Activity于onCreate()设“全局”状态(例如定义布局)并于onDestroy()释放全部资源。例如Activity有一后台运行线程,从网络上下载数据。它可能于onCreate()创建并于onDestroy()终止。参考OnDestroyvoid onDestroy ()该方法于活动销毁前做最后全部清理工
WPF内存、资源释放问题
在搜wpf相关资料时看到说wpf程序很耗内存,现在想优化下自己的程序。rnrn搜了下内存、资源释放的资料,什么GC啊、Dispose啊、托管资源啊、非托管资源啊都是这些,但看不懂。rnrn我想问下怎样可以简单优化自己的程序呢??rnrn例如定义了一个string s = "abc";是不是用完后,s = null;这样就会释放s的资源?rnrnwindow.Close()后,是不是该窗体的资源就释放了?不是的话要怎么释放??
请教HtmlHost资源释放的问题。
SilverLight下的控件 HtmlHost,在使用之后,如何把它释放,没有Dispose,没有Close。求教!
请问:关于资源释放的问题
VC++ 6.0 开发的Win32程序,用BoundsChecker进行内存泄漏检查。结果如下。rnrn HBITMAP hBitMap;rn BITMAP bm;rn HFONT hOldFont; rn HBITMAP hPrevBmp;rnrn HDC hdc = wglGetCurrentDC();rnrn if(!m_hFont) rn rn m_hFont = (HFONT)::GetStockObject(SYSTEM_FONT);rn rnrn hOldFont = (HFONT)SelectObject(hdc, m_hFont);rnrn ::GetTextExtentPoint32(hdc, m_szText, strlen(m_szText), &m_size);rnrn hBitMap = CreateBitmap( m_size.cx, m_size.cy, 1, 1, NULL);rn rn HDC hMemDC = ::CreateCompatibleDC(hdc);rnrn if(hMemDC)rn rn hPrevBmp = (HBITMAP)SelectObject(hMemDC,hBitMap);rn rnrn HFONT hPrevFont = (HFONT)SelectObject(hMemDC, m_hFont);rnrn ::SetBkColor(hMemDC, RGB(0, 0, 0));rn ::SetTextColor( hMemDC, RGB(255, 255, 255));rn ::SetBkMode(hMemDC, OPAQUE);rnrn TextOut(hMemDC, 0, 0, m_szText, strlen(m_szText));rnrn GetObject(hBitMap,sizeof(BITMAP),(void*)&bm);rnrn m_size.cx = (bm.bmWidth + 31) & (~31);rn m_size.cy = bm.bmHeight;rn int bufsize = m_size.cy * (((bm.bmWidth + 31) & (~31)) /8);rnrn if ( m_pBmpBits != NULL )rn rn delete []m_pBmpBits;rn m_pBmpBits = NULL;rn rnrn m_pBmpBits = new UCHAR[bufsize];rn memset(m_pBmpBits, 0, sizeof(UCHAR)*bufsize);rnrn struct rn BITMAPINFOHEADER bih;rn RGBQUAD col[2];rn bic;rn rn BITMAPINFO *binf = (BITMAPINFO *)&bic;rn binf->bmiHeader.biSize = sizeof(binf->bmiHeader);rn binf->bmiHeader.biWidth = bm.bmWidth;rn binf->bmiHeader.biHeight = bm.bmHeight;rn binf->bmiHeader.biPlanes = 1;rn binf->bmiHeader.biBitCount = 1;rn binf->bmiHeader.biCompression = BI_RGB;rn binf->bmiHeader.biSizeImage = bufsize;rn binf->bmiHeader.biXPelsPerMeter = 1;rn binf->bmiHeader.biYPelsPerMeter = 1;rn binf->bmiHeader.biClrUsed = 0;rn binf->bmiHeader.biClrImportant = 0;rnrn ::GetDIBits(hdc, hBitMap, 0, bm.bmHeight, m_pBmpBits, binf,DIB_RGB_COLORS);rnrn SelectObject(hMemDC, hPrevFont);rn SelectObject(hMemDC, hPrevBmp); // 错误提示:SelectObject usage error. Object already selected in to a Device Context.rn ::DeleteDC(hMemDC); // 错误提示:DeleteDC usage error. Device Context still contains objects.rnrn SelectObject(hdc, hOldFont);rn ::ReleaseDC( m_hWnd, hdc ); // 错误提示:ReleaseDC usage error. Device Context still contains objects.rnrn DeleteObject( hBitMap );rnrn请问这是怎么回事?谢谢!
线程资源释放有关问题!!!
VC SDK 下,用createthread()创建了一个线程.rn我的问题:rn1.当线程从上到下执行完毕后,线程中定义的变量等就被系统释放了呢?rn还是要释放线程的句柄后其中的变量才被释放?rn2.如果使用createthread()创建线程,该使用哪"两个"(我记得是两个)API函数才能完全释放线程资源?rn以前看过,忘记啦.现在写程序要用到,请帮忙:)rn
再问资源释放问题?
请问:rnform1.close;rnactive:=cafee;rnform1.free;rn有何区别?rn是否form1.close;关闭窗体并不释放窗体和其上控件占用资源?rnactive:=cafree;既关闭窗体又释放所有资源?rnactive:=cafree等同form1.free;?rn还有我试了一下active:=cafree;提示can't assign a read only property。rnwhy?rn再:释放了主窗体就不需释放其他窗体了吗?rn虽然问题简单,但是还请有人彻底解答!rn上个贴子没人回答彻底,希望这个能解吾之惑。
线程资源释放问题
我用vc6.0建立一个多文档应用程序,在一个类中(Test.CPP)启动了一个子线程,代码如下rn-------------------------------------------------------------------------rnm_pJabberClient=new xxxx(); 析构函数出错无法释放rnm_pMFTalkThread = AfxBeginThread( MFTalkMsgHandlerProc, m_pJabberClient, THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED );rn m_pMFTalkThread->m_bAutoDelete;rn ASSERT_VALID( m_pMFTalkThread );rn if ( ! m_pMFTalkThread )rn return FALSE;rnrn m_pMFTalkThread->ResumeThread();rnrn----------------------------------------------rn子线程函数rnUINT CMFTalkClient::MFTalkMsgHandlerProc( LPVOID lParam )rnrnrn xxxx* m_pJabberClient = static_cast< xxxx* >( lParam );rn while ( TRUE )rn rn ce =m_pJabberClient->recv();rn rnrnrn在该类的析构函数中delete m_pJabberClient时出错,该类中其他new的对象都能释放,大家帮忙看看这个对象为什么无法释放呢?
有关资源释放的问题!!!!急救!!!
一个程序,开始运行的时候就起了一个接收线程,准备接收UDP报。rnrn当和它的客户端通讯一阵后,关闭程序。在10秒内再启动该程序,就会非法。。。rnrnrn程序退出10多秒内,观察WIN2000下的系统性能检测,发现CPU利用率100%。只要没过100%,程序就无法启动,再启动就是非法!怎么回事????到底是什么资源没有释放,还是别的什么原因??????
关于fmodce.dll资源释放的问题
请教各位: 使用C#在Mobile上用fmodce.dll进行声音文件的播放,播放结束调用:rnbool isSuccess = fmod_Stop(this.m_SoundHandle); //返回truern fmod_Close();rnrn播放结束后需要删除该声音文件,但是发现还在被占用,无法删除,调用了:rn IntPtr temp = LocalFree(m_SoundHandle); //释放rn也没有效果,而且有时候还会在LocalFree上报错:异常代码:0xc0000005 异常地址:0x03f6bb60rnrn那么应该如何进行释放才能进行删除操作呢?谢谢!
关于BSTR资源释放的问题!
写了一个ATL控件,其中一个接口是这样定义的rn#include rnrnShowMsg(BSTR msg)rnrn USES_CONVERSION;rn ::MessageBox(NULL, W2A(msg), "Notice", 0);rnrn那么要不要释放BSTR类型占用的资源,如果BSTR占用资源的话。rn另外,对于BSTR的接口变量,为什么在Client端程序中可以直接用一般的字符串负值,而不要转换成BSTR类型。rnrnrn
导入的资源释放问题?
一般步骤就是:rnLoadResourcernCreateFilernWriteFilern但是CreateFile第一个参数已经指定了释放的路径目录,这样的结果就是rn先把资源释放到指定的目录中再使用rnrn现在的问题是:rn能否不释放到硬盘空间中而是直接释放到内存中来使用rnrn这样如何做呢?
Bitmap资源释放的问题,高分
在Picture框里显示Bitmap(位图有500KB):rnm_pic.SetBitmap(bitmap1);rnrn不需要显示时:rn::DeleteObject(bitmap1);rnrn资源释放后,系统监视器内存占用并没有减小。请问如何解决?rnrn
★★★数据库服务器资源释放的问题!!!
本人用ADOConnection连接数据库,用ADOQuery编写语句,用clear和close处理ADOQuery的释放,用connected和free处理ADOConnection的关闭。rnrn但为什么服务器的内存一直都是高居不下,令我苦恼,还请各位帮忙,谢谢!!!
GLUT 的资源释放问题
我使用malloc申请了一块内存,然后给它赋予特定的值,再调用GLUT去显示它,然后去free那块内存。rnrn然而当我调用GLUT去显示它后,看完关闭glut窗口程序却直接exit,并没有回到我的free代码段,怎么办?
关于cocos2d-x 资源释放问题
浅谈cocos2d-x游戏资源放问题
png按钮的资源释放问题
开发环境:vc2005 arm wince5.0rn我用网上下的CCePngButtonST类做png按钮,想要实现同一个按钮上的png图片根据不同情况显示不同内容,比如播放器打开时显示一张图片,播放器关闭时显示另一张图片,结果点了n次后把内存都占光了,显然是加载另一张时前一张的内存没有释放完,请问rn如何释放?rnrn代码如下:rn 1:rn CCePngButtonST m_cbtntest;rnrn rn BOOL CAlphaBlendDlg::OnInitDialog()rnrn CDialog::OnInitDialog();rnrn // Set the icon for this dialog. The framework does this automaticallyrn // when the application's main window is not a dialogrn SetIcon(m_hIcon, TRUE); // Set big iconrn SetIcon(m_hIcon, FALSE); // Set small iconrnrn // TODO: Add extra initialization herern this->ShowWindow(SW_SHOWMAXIMIZED); //SW_MAXIMIZE是显示窗口为最大化rn m_cbtntest.SetWindowPos(&wndTop,0,190,80,80,SWP_NOZORDER|SWP_SHOWWINDOW);rn m_cbtntest.SetImage(IDB_MAINBKGND,IDB_04,CSize(70,70),IDR_MUSIC,CSize(80,80));rnrn rnrnrn2. 事件判断rnrn if(i==0)rn m_cbtntest.SetImage(IDB_MAINBKGND,IDB_04,CSize(70,70),IDR_MUSIC,CSize(80,80));rn rn rn elsern m_cbtntest.SetImage(IDB_MAINBKGND,IDB_GAME1,CSize(70,70),IDR_GAME,CSize(80,80));rn rn3。 CCePngButtonST类中的函数rnrn DWORD CCePngButtonST::SetImage(int nBkgndID, int nImageIn, CSize sizeIn, int nImageOut, CSize sizeOut, int nImageDis, CSize sizeDis)rnrn IImage* pImageIn = NULL;rn IImage* pImageOut = NULL;rn IImage* pImageDis = NULL;rnrnrn nBkgndImageID = nBkgndID;rn CoInitializeEx(NULL,COINIT_MULTITHREADED);rn //initialize com rn if(!SUCCEEDED(CoCreateInstance(CLSID_ImagingFactory,NULL,CLSCTX_INPROC_SERVER,IID_IImagingFactory,(void **)&pIImgFactory)))rn rn return BTNST_FAILEDMASK;rn rn // Set image when the mouse is IN the buttonrn ImageFromIDResource(nImageIn, L"PNG", &pImageIn);rn // Set image when the mouse is OUT the buttonrn if (nImageOut)rn ImageFromIDResource(nImageOut, L"PNG", &pImageOut);rn // Set image when the mouse is DISABLEDrn if (nImageDis)rn ImageFromIDResource(nImageDis, L"PNG", &pImageDis);rn return SetImage(pImageIn, sizeIn, pImageOut, sizeOut, pImageDis, sizeDis);rn // End of SetImagernrnDWORD CCePngButtonST::SetImage(IImage* pIImageIn, CSize sizeIn, IImage* pIImageOut, CSize sizeOut, IImage* pIImageDis, CSize sizeDis)rnrn // Free any loaded resourcern FreeResources();rnrn if (pIImageIn)rn rn // Image when mouse over button?rn m_csImages[0].pIImage = pIImageIn;rn // Get image dimensionrn m_csImages[0].dwWidth = (DWORD)sizeIn.cx;rn m_csImages[0].dwHeight = (DWORD)sizeIn.cy;rn rn // Image when mouse outside button?rn if (pIImageOut)rn rn m_csImages[1].pIImage = pIImageOut;rn // Get image dimensionrn m_csImages[1].dwWidth = (DWORD)sizeOut.cx;rn m_csImages[1].dwHeight = (DWORD)sizeOut.cy;rn // ifrnrn // Image when button disabled?rn if (pIImageDis)rn rn m_csImages[2].pIImage = pIImageDis;rn // Get icon dimensionrn m_csImages[2].dwWidth = (DWORD)sizeDis.cx;rn m_csImages[2].dwHeight = (DWORD)sizeDis.cy;rn // ifrn // ifrnrn Invalidate();rnrn return BTNST_OK;rn // End of SetImagernrnrnrnvoid CCePngButtonST::FreeResources(BOOL bCheckForNULL)rnrn if (bCheckForNULL)rn rn // Destroy iconsrn // Note: the following lines MUST be here! even ifrn // BoundChecker says they are unnecessary!rn if (m_csIcons[0].hIcon) ::DestroyIcon(m_csIcons[0].hIcon);rn if (m_csIcons[1].hIcon) ::DestroyIcon(m_csIcons[1].hIcon);rn if (m_csIcons[2].hIcon) ::DestroyIcon(m_csIcons[2].hIcon);rn // ifrnrn memset(&m_csIcons, 0, sizeof(m_csIcons));rn memset(&m_csBitmaps, 0, sizeof(m_csBitmaps));rn memset(&m_csImages, 0, sizeof(m_csImages));rn // End of FreeResourcesrnrnrn
loadBitmap 资源释放问题
平台:rn windows cern EVC (MFC)rnrn代码:rn CBitmap bmp;rn bmp.LoadBitmap(IDB_BITMAP_A);rnrn ... ...rn [color=#FF0000]bmp.DeleteObject()[/color]rn bmp.LoadBitmap(IDB_BITMAP_B);rn ......rn问题:rn 在用CBitmap bmp 对象来加载第二张图(IDB_BITMAP_B)的时候,必须先bmp.DeleteObject(),如果不加的话,在debug模式下会出错,出错的地方是:rn [code=C/C++]rnBOOL CGdiObject::Attach(HGDIOBJ hObject)rnrn ASSERT(m_hObject == NULL); // only attach once, detach on destroyrn if (hObject == NULL)rn return FALSE;rn CHandleMap* pMap = afxMapHGDIOBJ(TRUE); // create map if not existrn ASSERT(pMap != NULL);rn pMap->SetPermanent(m_hObject = hObject, this);rn return TRUE;rnrn[/code]rnrn 起初以为是内存操作的原因要将bmp delete,后来看msdn:rnrnIf the bitmap identified by lpszResourceName does not exist or if there is insufficient memory to load the bitmap, the function returns zero.rnrn[b]You can use the CGdiObject::DeleteObject function to delete a bitmap loaded by the LoadBitmap function, or the CBitmap destructor deletes the object for you. [/b]rnrnBefore you delete the object, make sure it is not selected into a device context.rnrnThe following bitmaps are added to Windows versions 3.1 and later: rnrnOBM_UPARRROWI rnOBM_DNARROWI rnOBM_RGARROWI rnOBM_LFARROWI rnThese bitmaps are not found in device drivers for Windows versions 3.0 and earlier.rnrnIn Windows CE, when you use the CBitmap::LoadBitmap method to initialize a CBitmap object, the bitmap is read-only. [color=#FF0000]This is because Windows CE does not copy the bitmap into RAM, as the Windows-based desktop platforms do. In Windows CE, the bitmap only exists in a resource, which is part of the executable file of the program.[/color] When you select the bitmap into a device context, you cannot modify the device context—for example, by drawing text into it—because that would require the ability to write to the bitmap.rnrnWindows CE does not support any predefined bitmaps, so you cannot use any OBM_* values in the lpszResourceName parameter.rnrnBecause Windows CE 1.0 only supports a 2 bit gray scale palette, use bitmaps that are one bit per pixel (monochrome .bmp) or two bits per pixel (.2bpp).rnrnrn[color=#FF0000]问题一[/color]rn[b]说明位图并不会加载到ram里面去的,是这样吗?[/b]rn如果不是,就如msdn所说是exe模块的资源部分部分,rnBOOL CGdiObject::Attach(HGDIOBJ hObject) 代码里面就是在做这种映射吧?rnrnCHandleMap* pMap = afxMapHGDIOBJ(TRUE); // create map if not existrn必须是not exist才可以创建!rnrnrn[color=#FF0000]问题二:[/color]rn如果不deleteobject(),在release 模式下,程序照样可以运行,界面显示不会受影响,但在debug模式下就会报错, 必须先delete才可以! 怎么解释? 如果不delete,程序运行会出现怎么样的异常? 或者说对软件的健壮性有怎样的影响?rnrnrn rnrnrnrnrnrn
关于资源释放的问题
我在mvc2.0中,当用户提交一个请求后,由于要处理的数据量比较大我就运行了一个线程处理。在线程中生成一个db文件由于下载,当生成完毕之后,我在网页中点击下载提示:文件“D:\Train.db”正由另一进程使用,因此该进程无法访问此文件。[code=C#]rnpublic string startdb()rn rn Thread nonParameterThread = new Thread(new ThreadStart(TrainRun));rn nonParameterThread.IsBackground = true;rn nonParameterThread.Start();rn return "正在生成文件,请进行其它操作";rn rn[/code]rnTrainRun中主要是使用sqlite3.dll生成一个db文件,我已用sqlite3_close(db)关闭该文件,请问还需要其它操作才能释放该资源吗?谢谢了
【讨论】动态库资源释放问题
主线程main,后台线程back,动态库lib.sornrnmain创建back,back调用lib.so中的函数func,func调用了malloc。rnrn问题是:当main调用pthread_cancel杀掉back时,func尚未执行free释放动态内存,那么func中malloc的内存会自动释放吗?rn lib.so中的全局数据存放在何处,是main的数据段,还是在其他数据段?
关于资源释放的问题请教
[size=15px]1.在Fmainrs界面执行查询qry_yg,where [color=#FF0000]条件1[/color]。rn2.双击qry_yg的一条记录,打开rs_edit界面。rn rs_edit的formcreat事件中,写入rn DBEdit2.DataSource := (Fmain.RzPageControl1.ActivePage.Controls[0] as TFmainrs).DataSource1;rn DBEdit2.DataSource.DataSet := (Fmain.RzPageControl1.ActivePage.Controls[0] as TFmainrs).qry_yg;rn DBEdit2.DataField := '姓名';rn运行正确。rn3.在Fmainrs界面执行查询qry_yg,where [color=#FF0000]条件2[/color]rn这时提示:Acess violation at address 00403BFC.....。rnrn问题:是不是因为rs_edit界面退出时,没有释放qry_yg?rn如果需要释放qry_yg,应该在什么事件怎么写?rn[/size]
关于连接池资源释放的问题
/*rn请问,以下这段程序执行后,并未显式关闭连接,连接对象myConnection会不会Close?即使它被系统rn自动回收,那连接池中的连接资源是否被立即释放?rn*/rnpublic void CreateMyOdbcCommand() rnrn OdbcConnection myConnection = new OdbcConnection("DRIVER=SQL rn Server;SERVER=MyServer;Trusted_connection=yes;DATABASE=northwind;");rn string mySelectQuery = "SELECT * FROM Categories ORDER BY CategoryID";rn OdbcCommand myCommand = new OdbcCommand(mySelectQuery, myConnection);rn myCommand.CommandTimeout = 20;rnrn
TAPI资源释放问题
void CALLBACK LineCallback(DWORD hDevice,DWORD dwMsg,DWORD dwCallbackInstance,DWORD dwParam1,DWORD dwParam2,DWORD dwParam3);rnrn为什么有的时候LineHandles和LineApp 释放不了?rnrnstatic HLINE *LineHandles;rnstatic HLINEAPP LineApp;rnstatic DWORD LineHandleCount;rnCTeleAndSms::CTeleAndSms(void)rnrn LineHandleCount=0;rn teleTimeLong=0;rn talkTimeLong=0;rn startTime=0;rn talkStartTime=0;rn endTime=0;rnrnrnCTeleAndSms::~CTeleAndSms(void)rnrn RealseMobile();rnrnrnHRESULT CTeleAndSms::InitMobile()rnrn SetLastError(0);rn DWORD last;rn if (lineInitialize(&LineApp, g_hInst1,(LINECALLBACK)LineCallback, g_szAppWndClass, &LineHandleCount) == 0)rn rnrn LineHandles = new HLINE[LineHandleCount];rn for(DWORD i = 0; i < LineHandleCount; i++)rnrn rnrn int rc;rn DWORD ver;rn LINEEXTENSIONID extensionID;rnrn if ( lineNegotiateAPIVersion( LineApp, i, 0x00010000, 0x00020000, &ver, &extensionID) == 0)rnrn rnrn rc = lineOpen( LineApp,i,&LineHandles[i],ver,0,(DWORD)0,LINECALLPRIVILEGE_MONITOR|LINECALLPRIVILEGE_OWNER, LINEMEDIAMODE_INTERACTIVEVOICE,NULL);rn if(rc==0)rn rn /*LPHCALL lphCall;rn rc=lineMakeCall(LineHandles[i],lphCall,telephonNum,0,NULL);*/ rn TCHAR CallNumber[50];rn PHONEMAKECALLINFO pmci;rnrn lstrcpy(CallNumber,telephonNum);rn memset (&pmci, 0, sizeof(pmci));rnrn pmci.cbSize = sizeof(pmci);rn pmci.pszDestAddress = CallNumber;rn PhoneMakeCall (&pmci);rnrnrn rn rnrn rnrn elsern rn rn last=GetLastError();rn rn return S_OK;rnrnrnvoid CALLBACK LineCallback(DWORD hDevice, DWORD dwMsg, DWORD dwCallbackInstance, DWORD dwParam1, DWORD dwParam2, DWORD dwParam3)rnrnrnrn switch(dwMsg)rnrn rn case LINE_CALLSTATE://呼叫状态rn rn switch(dwParam1)rn rnrn case LINECALLSTATE_IDLE://没有呼叫rn rn if(LineHandleCount>0)rn rn for ( DWORD i=0; i0)rn rn for ( DWORD i=0; i0)//表示电话已经接通rn rn talkTimeLong=endTime-talkStartTime;//通话时间rn else//响铃时间rn rn teleTimeLong=endTime-startTime;//打电话时间rn rnrn if(LineHandleCount>0)rn rn for ( DWORD i=0; i0)rn rn for ( DWORD i=0; i
强制结束进程,资源释放问题??
Windows下:rn我想问的是:类似 浏览器程序(比如Maxthon),或 某些网游客户端,或 自己写的程序,我不是正常的退出,而是用“任务管理器”-->“结束进程”,这样,会不会有些内存没被释放?还是 只有 动态分配且还未手动释放的内存 才会这样?还是其他什么情况???rnrn如果,强制关闭进程会造成某块内存未释放,是不是别的程序就不能使用那块内存了?那是否会造成内存越来越小,机子逐渐变慢?只能重启还原内存??rnrnrn来个人帮我讲讲,这个流程,操作系统是处理的,微软是怎么说的??最好具体点,谢谢。
C#webbrowser资源释放问题
我在使用webbrowser进入到指定页面后,我调用dispose()方法释放资源。但GC还没有回收他以前。我再登入进指定页面后(重复登陆的话是会弹出对话框),这个时候webbrowser弹出了对话框。rn如何才能在dispose()后将他资源全部释放掉,如果调用GC.collect(2)第2代强制的话速度不好啊!各位有什么好的办法吗?
picturebox控件资源释放问题?
MyImage 定义为外部变量rnMyImage = new Bitmap(fileName); rn rn定时器中每次重新装载图像rn if (this.PictureBox.Image != null)rnrn this.PictureBox.Image.Dispose();rn this.PictureBox.Image = null;rnrnthis.ctrlPictureBox.Image = MyImage;rnrn编译时,提示参数错误rnrn修改为rnif (this.PictureBox.Image != null)rnrn this.PictureBox.Image.Dispose();rn this.PictureBox.Image = null;rnrnthis.PictureBox.Image = (Image)MyImage.Clone();rnrn图像显示时闪烁rnrn修改为rnif (this.PictureBox.Image != null)rnrn this.PictureBox.Image.Dispose();rnrnthis.PictureBox.Image = (Image)MyImage.Clone();rn内存递增rnrn各位老大看看,解释一下。谢谢了。rnrnrn
HBITMAP资源释放问题
首先声明是WIN32编程里面rnrn我定义了一个类,管理图像资源,里面有成员是HBITMAP类型的,构造函数里是LoadImage来加载图像,然后在draw方法里会知道界面,从外部传进来一个dcrnmemdc = CreateCompatibleDC(dc); //然后创建memdcrnorignalbitmap = (HBITMAP)SelectObject(memdc,handle); //选进memdc并保存原来的rnBitBlt(dc,rect.left,rect.top,rect.right-rect.left,titleheight,memdc,0,0,SRCCOPY); //绘图rnSelectObject(memdc,orignalbitmap); //将原来的还原rnDeleteDC(memdc); //释放memdcrn这是绘制部分,然后在image类的析构函数中,我调用DeleteObject释放HBITMAP资源rn在主函数里有dc的释放部分,都有rnrn我的问题来了rn为什么我加载了位图但是最后没有使用,我的程序就崩溃了呢rn主要体现在F5调试运行的时候什么事也没有rnCtrl+F5直接崩溃,0x……指令引用的内存0x……不能为readrn希望高手指点,感觉是内存泄露,可是没找到问题。
关于iocp资源释放问题!!!!!
rn服务器端软件:(共两个线程,主线程和工作线程)rnrn服务器和客户端一个保持tcp连接,且服务器为iocp投递一个WSARecv消息,此时程序处于这个状态下。rn在这种“静止状态”下,退出软件,主线程将会调用closesocket关闭服务器端socket。rn此时工作线程循环调用GetQueuedCompletionStatus检测到这个事件。rnGetQueuedCompletionStatus应该怎么处理这个资源释放流程?rnrn我理解:rn[color=#FF0000]第一步:主线程调用closesocket关闭socket了,GetQueuedCompletionStatus首先会正确返回,并且BytesTransferred变量为0 ,在这里进行资源释放。且GetQueuedCompletionStatus继续循环。rn第二步:因为iocp里面还有个未完成的WSARecv消息。而此时socket已经被关闭了,所以GetQueuedCompletionStatus返回失败,错误类型为ERROR_OPERATION_ABORTED 即 995。然后再进行资源释放。[/color]rn rn我理解的正确吗,程序是按照第一步再第二步来操作的吗?rn资源会重复释放吗?rn做过的朋友你们是怎么处理这样的流程。先谢了。rn
struts+spring+hibernate 数据库资源释放问题
DAO :rnrn public void saveOrUpdate(Object object) rn this.getHibernateTemplate().saveOrUpdate(object);rn rn rn rnrn public void deleteAll(List list) rn this.getHibernateTemplate().deleteAll(list);rn rnrn public List getAll(String hql, Object[] values) rn return values == null ? this.getHibernateTemplate().find(hql) : this.getHibernateTemplate().find(hql, values);rn rnrn public List getList(final Integer onePageRows, final Integer currentPage, final String hql, final Object[] values) rn return this.getHibernateTemplate().executeFind(new HibernateCallback() rn public Object doInHibernate(Session session) throws HibernateException, SQLException rn Query query = session.createQuery(hql);rn if (values != null) rn for (int i = 0; i < values.length; i++) rn query.setParameter(i, values[i]);rn rn return query.setFirstResult((currentPage - 1) * onePageRows).setMaxResults(onePageRows).list();rn rn );rn rnrn rnpublic Boolean executeTransaction(Map map)rn rn boolean tranResult = false ;rn SessionFactory sf =null;rn Session session =null;rn try rn sf = this.getHibernateTemplate().getSessionFactory(); rn session = sf.openSession(); rn session.beginTransaction(); rn Iterator it = map.entrySet().iterator(); rn while (it.hasNext()) rn Map.Entry entry = (Map.Entry) it.next() ; rn Object key = entry.getKey(); rn Object value = entry.getValue(); rn if(value.equals("save"))rn session.save(key);rn else if( value.equals("update"))rn session.update(key);rn else if( value.equals("delete"))rn session.delete(key);rn rn rn session.getTransaction().commit(); rn tranResult = true;rn catch(Exception e)rn session.beginTransaction().rollback();rn tranResult = false;rn e.printStackTrace();rn rn session.close();rn session.flush();rn return tranResult;rn rnrn数据源如下:rnrnrn rn net.sourceforge.jtds.jdbc.Driverrn rn rn rn rn rn sarn rn rn 123456rn rn rn 80rn rn rn 1rn rn rn 20rn rn rn 20rn rn rn 5rn rn rn rnrn rn rn rn rn rn rn rn rn rnrn rn rn org.hibernate.dialect.SQLServerDialectrn truern 20 rn rn rn rnrn rn rn rnrnrn但好像还有数据库连接用完的现象,求教高手
一个资源释放的问题.
我的资源文件里有 101 102 108 why vah rpv 这6个资源.rn我想把他们全部释放到C盘.rnrn101释放成C:\1.exern102------C:\2.exern108------C:\8.exernwhy------C:\rm\why.jpgrnvah------C:\rm\vah.rarrnrpv------C:\rm\rpv.txtrnrn释放一个资源我会.多个就不会了.rn请问这要怎么写才行.rn我是新手.请详细点.谢谢!
关于JDBC的资源释放问题
高手们,请看下面的代码, 请问资源释放是否正确,但为什么数据库中,总有没rn释放的cursor呢。(我用的是ORACLE数据库)rnrnrnArrayList alTaskExecList;rnPreparedStatement psExecInfoStmt;rnrn……rn……rnrn public synchronized int writeTaskExecInfo()rnrn if(alTaskExecList.isEmpty()==true)rn return -1;rn rn String sCmdLine="";rn String sSql="";rn TaskExecInfo mTaskExecRec = new TaskExecInfo();rn rn tryrn int iCount = alTaskExecList.size();rn int i;rn for(i=0;i
内存资源释放的问题!
MFC中,在主窗口的view上创建CHtmlView来浏览网页,然后关掉CHtmlView,内存却不释放,非要将主窗口最小化一下在复原主窗口,然后才会从任务管理器中看见内存释放掉了。这是咋回事?
关于窗口资源释放的问题
收到信息rnif(窗口存在)rn 相应动作……;rnelsern 创建窗口;rn 相应动作;rnrn关闭窗口:PostMessage(WM_CLOSE,NULL,NULL);delete(this);rnrn上面这段代码当中,当我第一次收到信息时会创建一个窗口,如果我不关闭这个窗口,则程序不会出错.当我关闭该窗口后,再收到信息,它执行的是if语句,而不是我想要的else语句。难道关闭窗口以后这个指针没有被释放,还指向原来的那块内存(只不过这块内存是无效的,而不是原有的窗口类)?rn请问这是为什么?如果要按照我的意向执行,我应该怎么做,谢谢了
C#winform问题!
要实现这样的一个功能:获取一个用户table(userID,password),动态的!要显示在窗体上,目前是以checkedlistbox做的,要实现这样的功能,当选中一个用户的时候会弹出一个新窗口,让对应的用户输入其密码,如果密码正确,则对应的checkbox选中,不正确则不选!该怎么做?rnrn或者是我的思路不对,还是要动态添加checkbox控件和事件?
c#winform问题
form大小改变后,如何使form中的dataGrid textbox panel等也随着form一起改变
有关资源释放的问题
我做了一个测试资源释放的程序:rnrn程序的设计思路如下:rn建立了三个Form,其中把Form1作为主Form,把Form2和Form3通过Project|Options|Forms移动动到Available forms中,rn想测试Finalization的执行顺序,但出现了异常错误,引起错误的地方在rnfinalizationrn if Form3<> nil then Form3.Free; //释放Form3rn这句。rn请问这是什么原因,怎么解决?请大虾帮忙?rnrn附:rnForm1的代码如下:rnunit Unit1;rnrninterfacernrnusesrn Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,rn StdCtrls;rnrntypern TForm1 = class(TForm)rn Button1: TButton;rn Button2: TButton;rn procedure Button1Click(Sender: TObject);rn procedure Button2Click(Sender: TObject);rn privatern Private declarations rn publicrn Public declarations rn end;rnrnvarrn Form1: TForm1;rnrnimplementationrnrnuses Unit2,Unit3;rnrn$R *.DFMrnrnprocedure TForm1.Button1Click(Sender: TObject);rnbeginrn if Form2 <> nil then Form2.ShowModal;rnend;rnrnprocedure TForm1.Button2Click(Sender: TObject);rnbeginrn if Form3 <> nil then Form3.ShowModal;rnend;rnrnend.rn----------------------------------------------------------------------------------rnrnForm2和Form3的代码如下:rn----------------------------------------------------------------------------------rnunit Unit2;rnrninterfacernrnusesrn Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;rnrntypern TForm2 = class(TForm)rn privatern Private declarations rn publicrn Public declarations rn end;rnrnvarrn Form2: TForm2;rnrnimplementationrnrn$R *.DFMrnrninitializationrn Form2 := TForm2.Create(Application); //创建Form2rnfinalizationrn if Form2 <> nil then Form2.free; //释放Form2rnend.rn----------------------------------------------------------------------------------rnunit Unit3;rnrninterfacernrnusesrn Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;rnrntypern TForm3 = class(TForm)rn privatern Private declarations rn publicrn Public declarations rn end;rnrnvarrn Form3: TForm3;rnrnimplementationrnrn$R *.DFMrnrninitializationrn Form3 := TForm3.Create(Application); //创建Form3rnfinalizationrn if Form3<> nil then Form3.Free; //释放Form3rnend.rn----------------------------------------------------------------------------------
相关热词 c#入门推荐书 c# 解码海康数据流 c# xml的遍历循环 c# 取 查看源码没有的 c#解决高并发 委托 c#日期转化为字符串 c# 显示问号 c# 字典对象池 c#5.0 安装程序 c# 分页算法