memory-leaks

RAII Failure - Why Does this C++ Code Leak? - throw in ctor in try block prevents dtor

不想你离开。 提交于 2021-02-10 13:10:37
问题 The output of the program below is: begin try Object() ctor begin catch Why is the Holder class's destructor not called? Is this a memory leak? Is it possible to call the Holder class's destructor without rethrowing? #include <iostream> #include <exception> class Object { public: Object() { std::cout << "Object() ctor" << std::endl; } ~Object() { std::cout << "~Object() dtor" << std::endl; } }; class Holder { public: Holder() :myObjectP( new Object() ) { throw std::exception(); } ~Holder() {

Transferring ownership of raw pointer to unique_ptr

删除回忆录丶 提交于 2021-02-10 06:16:05
问题 I have allocated a pointer with new operator and assigned the ownership of the memory to a new unique_ptr . Do I have to delete the pointer allocated using new? Is there a memory leak here? #include <iostream> #include <memory> using namespace std; int main() { int *a = new int; *a = 5; std::unique_ptr<int> auptr; auptr.reset(a); int *b = auptr.get(); cout << *b << endl; cout << *a << endl; return 0; } 回答1: When your code reaches return , you have three pointers ( a , auptr and b ) pointing

Transferring ownership of raw pointer to unique_ptr

一个人想着一个人 提交于 2021-02-10 06:15:36
问题 I have allocated a pointer with new operator and assigned the ownership of the memory to a new unique_ptr . Do I have to delete the pointer allocated using new? Is there a memory leak here? #include <iostream> #include <memory> using namespace std; int main() { int *a = new int; *a = 5; std::unique_ptr<int> auptr; auptr.reset(a); int *b = auptr.get(); cout << *b << endl; cout << *a << endl; return 0; } 回答1: When your code reaches return , you have three pointers ( a , auptr and b ) pointing

Threads are going to be renewed over time to try and avoid a probable memory leak

天大地大妈咪最大 提交于 2021-02-08 14:00:07
问题 I try to deploy my war file. But after success deployment. I get this log: [root@dfdfdf bin]# export JAVA_HOME="/usr/java/jdk1.8.0_112/" [root@dfdfdfdbin]# ./startup.sh Using CATALINA_BASE: /root/apache-tomcat-8.5.8 Using CATALINA_HOME: /root/apache-tomcat-8.5.8 Using CATALINA_TMPDIR: /root/apache-tomcat-8.5.8/temp Using JRE_HOME: /usr/java/jdk1.8.0_112/ Using CLASSPATH: /root/apache-tomcat-8.5.8/bin/bootstrap.jar:/root/apache-tomcat-8.5.8/bin/tomcat-juli.jar Tomcat started. [root@satubangau

Is it possible to shut down a D3D device?

旧时模样 提交于 2021-02-08 10:20:29
问题 I have a test that shows memory leak in my app: RAM usage increases 30-40MB per iteration, the profiler shows it’s in external code. Between the iterations, I shut down & then recreate D3D device. When I stopped doing that and just kept the device alive, it became good: The only difference is 2 interface pointers: ID3D11Device , and IMFDXGIDeviceManager . Is there a way to shutdown a D3D device so it releases the memory instead of leaking? As far as I understand, if I would have leaked a

Is it possible to shut down a D3D device?

最后都变了- 提交于 2021-02-08 10:19:23
问题 I have a test that shows memory leak in my app: RAM usage increases 30-40MB per iteration, the profiler shows it’s in external code. Between the iterations, I shut down & then recreate D3D device. When I stopped doing that and just kept the device alive, it became good: The only difference is 2 interface pointers: ID3D11Device , and IMFDXGIDeviceManager . Is there a way to shutdown a D3D device so it releases the memory instead of leaking? As far as I understand, if I would have leaked a

MySQLdb - cursor - memory leak?

元气小坏坏 提交于 2021-02-08 09:04:12
问题 I'm using MySQLdb under Python32 on Windows 7: Python 3.2.3 (default, Apr 11 2012, 07:12:16) [MSC v.1500 64 bit (AMD64)] on win32 >>> import MySQLdb as My >>> My.version_info (1, 2, 3, 'final', 0) I'm running service which calls this many times over and over and over again: cursor = self._connection._conn.cursor() cursor.execute(sql) for i in cursor.fetchall(): pass # Operation that is not important cursor.close() gc.collect() return set() # Will be filled with DB data And memory usage just

MySQLdb - cursor - memory leak?

左心房为你撑大大i 提交于 2021-02-08 09:03:29
问题 I'm using MySQLdb under Python32 on Windows 7: Python 3.2.3 (default, Apr 11 2012, 07:12:16) [MSC v.1500 64 bit (AMD64)] on win32 >>> import MySQLdb as My >>> My.version_info (1, 2, 3, 'final', 0) I'm running service which calls this many times over and over and over again: cursor = self._connection._conn.cursor() cursor.execute(sql) for i in cursor.fetchall(): pass # Operation that is not important cursor.close() gc.collect() return set() # Will be filled with DB data And memory usage just

How to fix CFRuntimeCreateInstance object leak?

可紊 提交于 2021-02-08 08:51:10
问题 I'm having unseen object leak (CFRuntimeCreateInstance) when profiling my app with instrument leak tool. I have rough imagination where the leak occurs but unable to spot it :) The call tree points me to my class method for loading an image from a spritesheet. Here is a fragment of the call tree (until leaking object CFRuntimeCreateInstance): +[ImageCache loadImageOfType:andIndex:] +[NSString stringWithFormat:] _CFStringCreateWithFormatAndArgumentsAux CFStringCreateCopy _

Is bash leaking memory?

一笑奈何 提交于 2021-02-08 05:55:09
问题 I'm running bash v4.4.19(1)-release on Ubuntu 18.10. If I run valgrind on a simple script (or even bash --version ), I'm seeing that I definitely lost 12 bytes of memory and there's on the order of 46kB still reachable. The still reachable memory doesn't bother me so much since I know bash is going to do it's thing with process handling and deallocation, but what I don't understand is why I'm losing these 12 bytes. Here's an example of a simple test script I'm using (filename is t.bash): #!