memory-leaks

Manually unpinning a byte[] in C#?

倾然丶 夕夏残阳落幕 提交于 2019-12-20 02:44:21
问题 In the following code, it seems that the client.Connect.Receive is pinning the "byte[] result" permanently, causing the memory to never be freed (as it's always pinned). I'm looking for a way to tell C# that result no-longer needs to be pinned after it's usage in this.OnReceive, but I can't find the built-in function or keyword to do this. Does anyone know how I can get C# to unpin the byte[] array? (this is one of the sources of memory leaks in my C# application) this.m_TcpListener = new

How return a std::string from C's “getcwd” function

≡放荡痞女 提交于 2019-12-20 01:58:35
问题 Sorry to keep hammering on this, but I'm trying to learn :). Is this any good? And yes, I care about memory leaks. I can't find a decent way of preallocating the char*, because there simply seems to be no cross-platform way. const string getcwd() { char* a_cwd = getcwd(NULL,0); string s_cwd(a_cwd); free(a_cwd); return s_cwd; } UPDATE2: without Boost or Qt, the most common stuff can get long-winded (see accepted answer) 回答1: If you want to remain standard, getcwd isn't required to do anything

About PropertyStore and MDI child form

霸气de小男生 提交于 2019-12-20 01:43:15
问题 This is .net WinForm question about MDI setting. When the main form creates an MDI child form, the main form's PropertyStore holds a reference to the MDI child form. I wonder whether this will cause the child form to be alive even if it is closed. If so, what shall I do when disposing the child form in order to remove this reference? The child form is called by sample code: //The code is in the main form. var f = new FormMDIChild(); f.MdiParent = this; f.Show(); 回答1: For the record, the

Does remove a DOM object (in Javascript) will cause Memory leak if it has event attached?

你。 提交于 2019-12-20 01:11:24
问题 So, if in the javascript, I create a DOM object in the HTML page, and attach event listener to the DOM object, upon I remove the the DOM from HTML page, does the event listener still exist and causing memory leak? function myTest() { var obj = document.createElement('div'); obj.addEventListener('click', function() {alert('whatever'); }); var body = document.getElementById('body'); // assume there is a <div id='body'></div> already body.appendChild(obj); } // then after some user actions. I

How built-in WPF controls manage their event handlers to an attached event?

て烟熏妆下的殇ゞ 提交于 2019-12-19 19:52:33
问题 I know that when you register an object to the mouse's attached events, you have memory leaks. That's why you need to use WeakEvent pattern. I have a problem with this pattern : If you want to use it, you cannot define your handler in the XAML code. To me, it means that every code like this leaks : <SomeControl Mouse.MouseDown="MyHandler" /> Unless you remove your handler explicitly in code (And I doubt that anybody does that). Now there is something I don't understand : <Button Click=

Ruby Symbol#to_proc leaks references in 1.9.2-p180?

我的梦境 提交于 2019-12-19 19:20:09
问题 Ok, this is my second attempt at debugging the memory issues with my Sinatra app. I believe I have it nailed down into simple sample code this time. It seems when I filter an array through .map(&:some_method) , it causes the items in that array to not get garbage collected. Running the equivalent .map{|x| x.some_method} is totally fine. Demonstration: Given a simple sample class: class C def foo "foo" end end If I run the following in IRB, it gets collected normally: ruby-1.9.2-p180 :001 > a

Ruby Symbol#to_proc leaks references in 1.9.2-p180?

▼魔方 西西 提交于 2019-12-19 19:19:31
问题 Ok, this is my second attempt at debugging the memory issues with my Sinatra app. I believe I have it nailed down into simple sample code this time. It seems when I filter an array through .map(&:some_method) , it causes the items in that array to not get garbage collected. Running the equivalent .map{|x| x.some_method} is totally fine. Demonstration: Given a simple sample class: class C def foo "foo" end end If I run the following in IRB, it gets collected normally: ruby-1.9.2-p180 :001 > a

FreeOSMemory() in production

元气小坏坏 提交于 2019-12-19 18:52:46
问题 I am using goroutines in a package where there is a tcp server. The response most of the time is very heavy, but when the routines end it is not cleared from the memory. func Handle() { service := ":7777" tcpAddr, err := net.ResolveTCPAddr("tcp4", service) checkError(err) listener, err := net.ListenTCP("tcp", tcpAddr) checkError(err) defer listener.Close() for { conn, err := listener.Accept() checkError(err) go handleRequest(conn, db) } } func handleRequest(conn net.Conn, db *sql.DB) {

SQLiteConnection databases leak when running emulator

自作多情 提交于 2019-12-19 13:59:12
问题 I was running the emulator and received the following errors about memory leak. It was interesting that the leaking database seems to be of the Google gms instead of a user database. Does anyone know how to fix it? Thanks! 09-27 15:55:07.252 2058-2068/com.google.android.gms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/user/0/com.google.android.gms/databases/metrics.db' was leaked! Please fix your application to end transactions in progress properly and to close the

SQLiteConnection databases leak when running emulator

拥有回忆 提交于 2019-12-19 13:59:03
问题 I was running the emulator and received the following errors about memory leak. It was interesting that the leaking database seems to be of the Google gms instead of a user database. Does anyone know how to fix it? Thanks! 09-27 15:55:07.252 2058-2068/com.google.android.gms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/user/0/com.google.android.gms/databases/metrics.db' was leaked! Please fix your application to end transactions in progress properly and to close the