memory-management

Understanding when to call retain on an object?

你。 提交于 2019-12-30 09:26:52
问题 When should retain be used ? I understand that it increments the object references count, so basicly the next release on that object will not call dealloc on it. Ok great, so what ? I read around that it's some kind of convention, that if you care about an object, you retain it. Is there any examples of that out there ? Is that even true ? EDIT: I'm not looking for when the debugger tells you to do that or this. So, I looked into this. To put it in my words, here's an example of a retain

How to read the debug memory window in Visual Studio

。_饼干妹妹 提交于 2019-12-30 08:33:52
问题 I have used debug mode in Visual Studio before, but I never had to use the memory window. If I had a simple application that calculates a=b+c and made b =8 and c=-2, how can I find the addresses a, b, and c in memory window and their values without using watches? When I tried, I saw tons of "gibberish" that I cannot make much sense of. Here's a screenshot: If I wanted to do the same, but in a Linux environment, how could I achieve this? 回答1: One way to find the address of a variable in Visual

OutOfMemoryException for a vb.net application

喜夏-厌秋 提交于 2019-12-30 08:27:08
问题 In one of my VB.Net applications i am getting error while running the application. This error does not come always. So i am not able to reproduce the error also. No exact sequence also to reproduce the error. Stack :System.OutOfMemoryException: Out of memory. at System.Drawing.Graphics.FromHdcInternal(IntPtr hdc) at System.Windows.Forms.ToolStrip.OnPaint(PaintEventArgs e) at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs) at System

std::unique_ptr<T[]> and custom allocator deleter

时间秒杀一切 提交于 2019-12-30 08:23:15
问题 I am trying to use std::unique_ptr<T[]> with custom memory allocators. Basically, I have custom allocators that are subclasses of IAllocator , which provides the following methods: void* Alloc( size_t size ) template<typename T> T* AllocArray( size_t count ) void Free( void* mem ) template<typename T> void FreeArray( T* arr, size_t count ) Since the underlying memory might come from a pre-allocated block, I need the special ...Array() -methods to allocate and free arrays, they allocate/free

Increasing memory limit in Python?

一曲冷凌霜 提交于 2019-12-30 08:14:39
问题 I am currently using a function making extremely long dictionaries (used to compare DNA strings) and sometimes I'm getting MemoryError. Is there a way to allot more memory to Python so it can deal with more data at once? 回答1: Python doesn’t limit memory usage on your program. It will allocate as much memory as your program needs until your computer is out of memory. The most you can do is reduce the limit to a fixed upper cap. That can be done with the resource module, but it isn't what you

Are Python docstrings and comments stored in memory when a module is loaded?

℡╲_俬逩灬. 提交于 2019-12-30 08:12:26
问题 Are Python docstrings and comments stored in memory when a module is loaded? I've wondered if this is true, because I usually document my code well; may this affect memory usage? Usually every Python object has a __doc__ method. Are those docstrings read from the file, or processed otherwise? I've done searches here in the forums, Google and Mailing-Lists, but I haven't found any relevant information. Do you know better? 回答1: By default, docstrings are present in the .pyc bytecode file, and

Are Python docstrings and comments stored in memory when a module is loaded?

半世苍凉 提交于 2019-12-30 08:11:27
问题 Are Python docstrings and comments stored in memory when a module is loaded? I've wondered if this is true, because I usually document my code well; may this affect memory usage? Usually every Python object has a __doc__ method. Are those docstrings read from the file, or processed otherwise? I've done searches here in the forums, Google and Mailing-Lists, but I haven't found any relevant information. Do you know better? 回答1: By default, docstrings are present in the .pyc bytecode file, and

When will the new String() object in memory gets cleared after invoking intern() method

你说的曾经没有我的故事 提交于 2019-12-30 06:53:07
问题 List<String> list = new ArrayList<>(); for (int i = 0; i < 1000; i++) { StringBuilder sb = new StringBuilder(); String string = sb.toString(); string = string.intern() list.add(string); } In the above sample, after invoking string.intern() method, when will the 1000 objects created in heap (sb.toString) be cleared? Edit 1: If there is no guarantee that these objects could be cleared. Assuming that GC haven't run, is it obsolete to use string.intern() itself? (In terms of the memory usage?) Is

Unable to use custom allocator with allocate_shared/make_shared

邮差的信 提交于 2019-12-30 06:17:10
问题 In my C++11 program, I use shared_ptr<T> for some objects which are actively created and deleted. It so happened that standard allocator with operator new is a bottleneck, so I want to create my own one, which will allocate a bunch of memory at once and then give to to make_shared on demand. Unfortunatelly, this is the first time I write an allocator and I have no idea why GCC is unable to compile the following code: #include <memory> class MyAlloc { public: typedef char* pointer; typedef

Why Does Looping Beat Indexing Here?

久未见 提交于 2019-12-30 06:13:07
问题 A few years ago, someone posted on Active State Recipes for comparison purposes, three python/NumPy functions; each of these accepted the same arguments and returned the same result, a distance matrix . Two of these were taken from published sources; they are both--or they appear to me to be--idiomatic numpy code. The repetitive calculations required to create a distance matrix are driven by numpy's elegant index syntax. Here's one of them: from numpy.matlib import repmat, repeat def