Menu
  • HOME
  • TAGS

Memory management in Contiki-OS

memory-management,heap-memory,contiki

All required memory is statically allocated during compilation/linkage. Its done by the PROCESS Macro[1], which allocates a structure containing the necessary information [2]. As for the events, they must allocate their own memory, too[3]. It is therefore not possible to run the same thread* or schedule the same event twice....

Temporary variable destroyed with overloaded + and += operator

c++,memory-management,operator-overloading

That's exactly how it should happen. It is probably more correct to say that it is not temporary b1 + b2 that gets destroyed, it is temporary Bcd(*this) += rhs inside your implementation of binary + that gets destroyed. Your implementation of + const Bcd& Bcd::operator +(const Bcd &rhs) const...

Java how to limit number of threads acting on method

java,multithreading,memory-management

You can use the Executor.newFixedThreadPool idiom, internally to your execution logic. Full example below: public class Main { public static void main(String[] args) throws Exception { Main m = new Main(); // simulating a window of time where your method is invoked continuously for (int i = 0; i <...

Allocate 2D Array in C (not array of pointers) in Heap

c,arrays,pointers,memory-management,allocation

You don't need a special function. Just do it like this double (*A)[n][m] = malloc(sizeof *A); As of C99, here n and m can be any positive integer expressions you want. Such a thing is a pointer to a VLA, variable length array....

URLClassLoader Memory Leak Java

java,memory-management,memory-leaks,urlclassloader

just add the dependency of class loader leak preventer in your build path. maven dependency for this is : <!-- For Classloader leak protection --> <dependency> <groupId>se.jiderhamn</groupId> <artifactId>classloader-leak-prevention</artifactId> <version>1.8.0</version> </dependency> ...

libXML: check if node is already unlinked and freed

memory-management,xpath,libxml2,vala

I'd suggest another way around to achieve the same. You can use a more specific xpath, so that in case there are nested elements having style attribute contains "display:none", only the outer-most elements gets selected : //*[contains(@style,'display:none')][not(ancestor::*[contains(@style,'display:none')])] ...

Retain cycle in Swift when Object A has Object B as a property and Object B has an array property that contains Object A?

ios,swift,memory-management,memory-leaks,retain-cycle

Generally speaking, with manual reference counting and automatic reference counting, reference ilands will leak. Reference cycle can be composed by more than just 2 objects. That said I encourage you to test some code in a playground since the example in your question has some syntax and language errors. The...

Weak and strong property implementation

objective-c,memory-management

For the first and second Q I refer to @rmaddy's comment and Christian's answer. So, actually i want to know, whether retain count decremented each time, when method that own variable finishes? First I want to be more precise: When you say "when method that own a variable finishes" you...

Objective-C memory leak when returning NSString

ios,objective-c,iphone,memory-management,memory-leaks

What you posted is OK. The only rule at this point is that methods contain "create" or "alloc" will return an object that needs to be explicitly released. In your case that is the string returned in the readString method. Since the object will be returned you need to retain...

How will you free the memory allocated?

c,memory-management,malloc,free,dynamic-memory-allocation

It's simple. You can use this code to clean your only used variable. #include<stdio.h> #include<stdlib.h> #define MAXROW 3 #define MAXCOL 4 int main() { int **p, i, j; p = (int **) malloc(MAXROW * sizeof(int*)); free(p); return 0; } ...

Should I outsource allocation algorithm? (RAII)

c++,memory-management,raii

struct Register { Register(): _trampoline_address(allocate()) {} Register(Register const& o): Register() // forward to default ctor { copy_data_from(o); } ~Register() { if (_trampoline_address) debug(VirtualFree(_trampoline_address, 0, MEM_RELEASE)); } Register& operator= (const Register& o) { if (this != std::addressof(o)) copy_data_from(o); return *this; } private: void copy_data_from(Register const& o) { Assert(_tranpoline_address); // ... }...

calloc created array is not acting as expected

c++,pointers,memory-management,calloc

Probably your debugger doesn't know how big buffer_buffer is, since that variable is simply declared as being a pointer to an int. (That's not correctly typed; buffer_buffer is used to hold values of buffer which is an int*, so buffer_buffer must be an array of int*, which means that you...

Large memory pages and fragmentation

linux,memory-management,shared-memory,ppc

kernel will assign 64KiB for each request less than 64 KiB.

Retain cycle with parent-child construction

ios,objective-c,memory-management,memory-leaks,retaincount

The word you are looking for is "retain cycle". The simplest retain cycle would be an object having a strong reference to itself. Very rare because it is rather pointless. The most common case is A having a strong reference to B and B having a strong reference to A....

Is BitSet worth using?

java,memory-management,bitset

BitSet will be less memory, using only one bit is far more efficient. The method overhead you are looking at is once no matter how many instances of your class you have, so its cost is amortized basically to 0 The advantage of a boolean over an array of booleans...

munmap_chunck(): invalid pointer in c

c,pointers,memory-management,global-variables

This is a common problem which occurs when you provide free a pointer which doesn't point to the start of an allocated memory block. For example, the code int* something = malloc(sizeof(int)); // Allocate space for 1 int ... free(something); will work fine as you are providing free with the...

Efficiently transferring elements between arrays

javascript,arrays,optimization,memory-management,data-structures

splice is pretty harmful for performance in a loop. But you don't seem to need mutations on the input arrays anyway - you are creating new ones and overwrite the previous values. Just do function doTransfers() { var A_pending = []; var B2_pending = []; for (var i = 0;...

Local const in recursion call

python,memory-management,recursion

I don't see any problems with a MAGIC_SPELLS constant. You can locale it near the magic function, so you know, the belong together: def magic_default(node): return magic(node.l) + magic(node.r) MAGIC_SPELLS = { 'AR_OP': ar_op_magic, 'PRE_OP': pre_op_magic, } def magic(node): if node: func = MAGIC_SPELLS.get(node.text, magic_default) return func(node) return "" ...

memory content not erased after deleting my pointer (on a simple example) [duplicate]

c++,pointers,memory-management

It may or may not print the same value after delete operation. So simply what you are observing is an undefined behavior.

What is a “non-weak zeroing reference”

objective-c,cocoa,memory-management,nsnotificationcenter,osx-elcapitan

The answer for this lies deep within the objective-c runtime, and how __weak variables actually work. To explain, let's look a little bit at objc_weak.mm: id weak_read_no_lock(weak_table_t *weak_table, id *referrer_id) { ... if (! referent->ISA()->hasCustomRR()) { if (! referent->rootTryRetain()) { return nil; } } else { BOOL (*tryRetain)(objc_object *, SEL)...

function to get 2d-arrays from stack and heap

c,arrays,memory,memory-management,malloc

If you try to do this in c or c++: int test[][]; you will get this error: error: declaration of 'test' as multidimensional array must have bounds for all dimensions except the first This is because test is not in fact a double ponter as you'd expect. But the compiler...

Is free() zeroing out memory?

c,gcc,memory-management,clang,free

There's no single definitive answer to your question. Firstly, the external behavior of a freed block will depend on whether it was released to the system or stored as a free block in the internal memory pool of the process or C runtime library. In modern OSes the memory "returned...

Strange error while adding a feature to my little game (0xC0000005)

c,memory-management,memory-leaks,heap-memory

First, you don't allocate your two-dimensional fields correctly. The "outer" field must hold int *, not just int: mineArray = calloc(10, sizeof(*mineArray)); for (i = 0; i < 10; i++) { mineArray[i] = calloc(10, sizeof(*mineArray[i])); } Another potential source of the segmentation fault is that Y might end up uninitialised...

S_realloc: How to increase the length of a *numeric* vector? (first argument not char*)

c,r,memory-management

That should be as easy as adding a cast foo = S_realloc((char*) p, n1, n2, n3); where p is your double *p. There is also an alternate form TYPE* Calloc(size_t N, TYPE) TYPE* Realloc(ANY *P, size_t N, TYPE) void Free(ANY *P) per Section 6.1.2 User-controlled Memory of Writing R Extensions....

Memory address in linked list C++

c++,memory-management,linked-list

You're printing: "Current Add:\t" << &cur << endl << This is the address of the variable: struct node *cur; The address of that pointer (not the address it points to!) will of course not change. You probably intended to write: "Current Add:\t" << cur << endl << ...

When calling append on stringbuilder, are we adding strings to the heap?

c#,.net,memory-management,stringbuilder

are we not creating a string that is then used from the stringBuilder, to be appended and added to the internal character array - buffer ? In your correct example, yes. The string has to be first allocated and then added to the internal buffer. But imagine you have...

Free memory of byte[]

c#,memory-management

At the core, the problem is that you read from your file in one big chunk. If the file is very large (greater than 85,000 bytes to be precise), then your byte array will get stored in the LOH (large object heap). If you read up on the 'large object...

Memory analysis in Android: dominator_tree does not show all the instances of some objects

java,android,eclipse,memory-management,eclipse-memory-analyzer

Analyzing the results that are shown in the dominator_tree I have understand what happened: The dominator three show only the objects that have at least one path from GC root to them. It requires at least one reference for being shown in that diagram (It doesn't metter if is a...

At what size should I malloc structs?

c,memory-management,struct,malloc

Good code gets re-used. Good code have few size limitations. Write good code. Use malloc() whenever there is anything more than trivial buffer sizes. Buffer size to write an int: The needed buffer size is at most sizeof(int)*CHAR_BIT/3 + 3. Use a fixed buffer. Buffer size to write a double...

Core Data One-To-Many Relationship Memory Usage

ios,core-data,memory-management,one-to-many

There are NUMEROUS disadvantages to not specifying an inverse. You will have poorer performance, Core Data will need to work harder and you risk integrity issues. Always, always, always have an inverse relationship. Even if you will never use it, Core Data will. You will not have a memory issue...

Getting many memory errors when try to run it for few days in my web crawler [on hold]

java,memory,memory-management,out-of-memory

I tried to allocate memory by changing eclipse.ini setting to 2048 MB of ram as it was answered in this topic but still get the same errors after 3 hours or less. I hate to repeat myself(*), but in eclipse.ini you set up the memory for Eclipse, which has...

Memory error in set resize

c,memory-management

In your function you are taking the pointer into to_resize, then you realloc the memory, but you never set the new pointer back to the set->state_array[slot_i], so it is lost and you keep on using the old, already freed memory space and will point outside its bounds.

Why should I dimension my variables in VBA really?

vba,memory-management

Memory usage is only pleasant a side effect. The real reason I'd recommend using Option Explicit is that it allows the compiler to protect you from coding mistakes that compile and run, but don't do what you intend. Example 1: It keeps typos from turning into unexpected disasters. Dim variableNamedFoobar...

Cannot free fileName char * after fclose

c,memory-management,malloc,free,realloc

You code is having issue in the below line strcat(*indexFileName, ".ind") the destination buffer at *indexFileName is having insufficient memory to hold the concatenated string. Hence it invokes undefined behaviour. From the man page of strcat() ... If dest (destination buffer) is not large enough, program behaviour is unpredictable; So,...

Sharing std::string across shared memory

string,c++11,memory-management

I wish to share a std::string across processes using shared memory. You cannot share non-POD types across process boundaries, especially types that may allocate memory internally. There is no guarantee that the other processes use the same version of the STL, if they use the STL at all. And...

malloc() - Does it use brk() or mmap()

c,memory-management,malloc,mmap,sbrk

If we change the program to see where the malloc'd memory is: #include <unistd.h> #include <stdio.h> #include <stdlib.h> void program_break_test() { printf("%10p\n", sbrk(0)); char *bl = malloc(1024 * 1024); printf("%10p\n", sbrk(0)); printf("malloc'd at: %10p\n", bl); free(bl); printf("%10p\n", sbrk(0)); } int main(int argc, char **argv) { program_break_test(); return 0; } It's...

Why I cannot use “fgets” to read a string to an element of my Struct?

c,pointers,memory-management,struct,fgets

Problems that I see: You are allocating the wrong amount of memory in the line: vet = (CLIENTES*)malloc(num*sizeof(int)); That should be: vet = malloc(num*sizeof(*vet)); See Do I cast the result of malloc?. The answers explain why you should not cast the return value of malloc. You are using fgets after...

Fast memory allocation for real time data acquisition

c++,memory-management

The idea for solving this type of problems can be as follows: Separate the problem into 2 or more processes depending what you need to do with your data: Acquirer Analyzer (if you want to process data in real time) Writer Store data in a circular buffer in shared memory...

How are Strings created and stored in Java?

java,string,memory-management,immutability,hashcode

You have created String literals and String objects. String literals like s1 and s2 are stored in the String pool. as they are the same String they have the same reference. This is efficient. String objects created using the new keyword result in an object that is stored on the...

xCode 6.3.2 Crash [UIViewController .cxx_destruct]

objective-c,xcode,core-data,memory-management

// Code which caused [UIViewController .cxx_destruct] Article *article = [Article new]; // Fixed with this NSManagedObject *article = [NSEntityDescription insertNewObjectForEntityForName:@"Article" inManagedObjectContext:context]; ...

free() and mxFree() in MATLAB - freeing memory twice

matlab,memory-management,free,mex

The second loop does not index correctly for tau. You are defining indexing for tau as #define tau(a, b) tau[b+a*NrSensor] Let us walk through the second loop assuming NrSensor = 10 and len_zr = 5. For this case max value of loop variable i is 9 and max value of...

When do I need to free a Data Module created by the Application?

delphi,memory-management,datamodule

Answer to your question "When do I need to free a Data Module created by the Application?" is never. All data modules and/or forms created with Application.CreateForm method will be owned by Application and automatically handled. But as it seems, you issues are not related to automatic destruction process. Following...

Fortran memory allocation does not give an error, but the program is killed by OS at initialization

memory-management,fortran

You are seeing the behavior of the memory allocation strategy linux uses. When you allocate memory but have not written to it, it is solely contained in virtual memory (note this may also be affected by the particular Fortran runtime library, but I'm not sure). This memory exists in your...

HTTPNetStreamInfo::_readStreamClientCallBack(__CFReadStream*, unsigned long) increases memory allocation

ios,memory,memory-management,xamarin,httpclient

Strange but yes, it is fixed in iOS8.3. NSURLCache was broken in iOS 8.x till iOS8.3. So it was not able to clear the cache. But as I have updated it to iOS8.3, it came down to 32KB block and consumes max 5-7MB.

Does free() set errno?

c,linux,memory-management

POSIX doesn't define free to set errno (although POSIX doesn't currently forbid it, so an implementation might do so - refer to @ArjunShankar's answer for more details). But that's not really relevant to your concern. The way you're checking for errors is incorrect. You should check the return value of...

Allocating memory for pointers inside structures in functions

c,pointers,memory-management,struct

Code with comments: void f_alloc(ssm **a) { *a = malloc(sizeof(ssm)); // Need to allocate the structure and place in into the *a - i.e. hello in main (*a)->p = malloc(sizeof(int)); // Allocate memory for the integer pointer p (i.e. hello ->p; } EDIT I think this is what you are...

Most efficient way to clone a list into an existing list, minimizing memory reallocation?

c#,performance,list,memory-management,clone

if (destination.Capacity < source.Capacity) { /* Increase capacity in destination */ destination.Capacity = source.Capacity; } This is probably wrong... The source.Capacity could be bigger than necessary... And you are "copying" the elements already contained in destination to a "new" destination "buffer". This copy is unnecessary because then the elements of...

Using mmap and madvise for huge pages

c,linux,memory-management,mmap,huge-pages

Both functions perform different operations, which may or may not matter in your context: madvise sets a flag for all the memory mappings corresponding to the region passed to it, telling the khugepaged kernel thread that it can consider said mappings for promotion to huge pages. That will only work...

When do autorelease pools drain?

ios,objective-c,memory-management

The documentation is not specific on when the "main" autorelease pool drains, but generally you can assume it is drained at the end of the application's main event loop. Here's what happens with regards to autorelease pools: An autorelease pool is created when an application starts. When another pool is...

How to get current memory page size in C#

c#,.net,memory-management

Try Environment.SystemPageSize: Gets the number of bytes in the operating system's memory page. Requires .NET >= 4.0 In the remarks it is even written that: In Windows, this value is the dwPageSize member in the SYSTEM_INFO structure. ...

Disadvantages of calling realloc in a loop

c,memory-management,out-of-memory,realloc

When you allocate/deallocate memory many times, it may create fragmentation in the memory and you may not get big contiguous chunk of the memory. When you do a realloc, some extra memory may be needed for a short period of time to move the data. If your algorithm does...

Why this memory management trick works?

c#,memory-management,unity3d

It's not really a trick. It's the way that parts of Unity3D handle memory. In Unity3D you have objects that are handled by Mono and will be garbage collected, and objects that are handled by Unity, that will not be garbage collected. Strings, ints etc are cleaned up by Mono...

Is there a better way to do this than writing a wrapper allocator that stores a reference to a stateful allocator object?

c++,memory-management,lambda,allocator,std-function

The standard "Allocator" concept would have been better named "AllocatorReference." Each object either refers to a global instance (stateless) or to an external object (stateful). Either way, the allocator instance within an allocator-aware container does not own a memory pool by itself. It's only a proxy. Note that allocator objects...

How can I ensure an emxArray is correctly allocated in generated C code?

matlab,memory-management,matlab-coder

It's good to see that you're making progress. Regarding the emxEnsureCapacity issue it is unfortunate and it is a bug. I'll take care of it to ensure we fix it in a forthcoming release. Meanwhile, there's a way of patching the generated source code. For config objects there's the 'PostCodeGenCommand'...

Using a data pointer with CUDA (and integrated memory)

c++,memory-management,cuda

The pointer has to be created (i.e. allocated) with cudaHostAlloc, even on integrated systems like Jetson. The reason for this is that the GPU requires (zero-copy) memory to be pinned, i.e. removed from the host demand-paging system. Ordinary allocations are subject to demand-paging, and may not be used as zero-copy...

Necessary to delete dynamic struct contents, and then the struct itself?

c++,memory-management

The issue actually stems from here: bread->name = "bread"; After allocating a new array for name, you are assigning that pointer to a completely different value - one that happens to live in read-only memory. Hence the error when you delete it: you're trying to delete [] an array that...

Using parse.com and having allocation memory issue

android,memory,memory-management,parse.com,allocation

If you are using parse.com and getting the Images from database and converting it to bitmaps it will crash your app.. what you should do is, get the image of the URL from parse.com there is method called.. ParseFile.getUrl(); For that implement the Picasso library, which is perfect solution for...

c++ dynamically declared array fails to work

c++,memory-management,new-operator,theory,heap-memory

save yourself loads of trouble, use a vector std::vector<double> data; data.reserve(SIZE_OF_ARRAY); // not totally required, but will speed up filling the values vector will give you better debug messages and you won't have to deal with memory yourself....

Simple explanation about loading files into memory

vb.net,visual-studio-2010,memory-management

When they refer to reading something "into memory" it is simply a way of saying that you are reading it and storing it in a variable (which stores it in memory). Use ReadAllLines to read the entire file into memory: Dim readText() As String = File.ReadAllLines(path) See File.ReadAllLines Method (String)...

Managing memory of Vector3's created to move gameObject

c#,memory-management,memory-leaks,unity3d

It creates a new Vector3 every FixedUpdate() (60 times per second, by default), even if user is not providing input. Vector3 created on a stack. And releasing once you left function. (No garbage collection) When you assign a variable movement to rigidbody.velocity, you are simply copying struct. (No garbage...

Is the memory assigned to a strong property released as soon as the property is set to nil?

objective-c,memory-management,automatic-ref-counting

Assigning nil to a strong variable does indicate that you no longer need the object the variable is referencing, and provided no other strong references to the object exist ARC will dispose of the object quickly, if not immediately. Your object is probably (see end) referenced by the autorelease pool,...

Operator Overloading without memory copies

c++,memory-management,operator-overloading

Before C++11, it depends on your compiler. The standards permit, but do not require, the compiler to eliminate (or elide) temporaries where the only way of detecting their existence is to track constructor and destructor calls. This is one case where that is permitted. In C++-11, look up rvalue references...

Valgrind says about “Invalid write” in fclose()

c++,memory-management,valgrind

It was my fault. I wrote that I use fmemopen() to open a stream, but this code wasn't running, and I get stream, produced earlier with open_memstream(). Although this stream was opened for writing, I can read from it. However valgrind reports about problem. I fixed my code, valgrind find...

Modern C++ idiom for allocating / deallocating an I/O buffer

c++,memory-management,io

Basically, you have two main C++-way choices: std::vector std::unique_ptr I'd prefer the second, since you don't need all the automatic resizing stuff in std::vector, and you don't need a container - you need just a buffer. std::unique_ptr has a specialization for dynamic arrays: std::unique_ptr<int[]> will call delete [] in it's...

How to translate these logical addresses into physical addresses?

memory-management,operating-system

In your model, the page table entry is address DIV page-size the offset is address MOD page-size I don't know if your addresses are hex or decimal. I will assume hex. For your first example--20 page table entry = 0 page offset = 20 Your page table entry 0 maps...

QEvent ownership

c++,qt,memory-management

event = &stackevent; //valid ?? Usually that's not safe, but in this case it's valid, because the function notify won't return, untill the event is handled (or not) by someone (it means that stackevent will be "alive" during this operation). delete heapevent; //valid? or lost ownership? Yap, that's valid...

Understanding Stack, Heap and Memory Management

c++,pointers,memory-management,stack,heap

The sequence is correct except one point: The delete []ip; removes the memory allocated on the heap to the ip pointer. The pointer that got passed through to myFun now points to nothing. The pointer doesn't point to 'nothing' (i.e. isn't set to nullptr or 0 after freeing the memory)....

DataTable does not release memory

c#,memory,memory-management,datatable

Your main problem is the behavior of the Garbage Collector is different depending on if you are debugging or in release mode without a debugger present. When in a debug build or a release build with a debugger present all objects have their lifetimes extended to the entire lifetime of...

emptying an std::queue through a function that returns the front() and pops()

c++,memory-management,destructor

In case I get it right, the problem is the lack of a user-defined assignment operator for FileEntry. Your copy constructor takes care of the fact that each FileEntry has a new FolderInfo if the copied FileEntry has freeFolderInfo == true, whereas your assignment operator does not. If you assign...

C++ vector only save the last push_back value

c++,memory-management,vector,push-back

I invite you over to my house, giving you my address which you hastily note down on paper. You come over and see that my house has green walls. The next day, you copy the address into your phone's address book for safekeeping. A few months later, I repaint...

Where C++ calls destructors?

c++,class,memory-management,destructor

At which point does C++ call destructor of each m1, m2 and lst? The destructors are called at the end of the scope, in the reverse order of the objects definitions. In your case, func1() is first called, which defines lst, then calls fillList(), which defines m1 and m2....

Host testing C program with hard coded memory addresses

c,linux,unit-testing,memory-management,functional-testing

You could check for e.g. the __linux__ macro and use conditional compilation. When on Linux use an array as base, and make it big enough to keep all the data needed in it. Something like e.g. #ifdef __linux__ int8_t array[1024]; # define MY_BASE_ADDRESS array #else # define MY_BASE_ADDRESS 0x00600000 #endif...

Unable to increase PHP Memory Limit

php,apache,memory,memory-management,out-of-memory

So it turns out the memory limit was being increased properly, just not being reflected in phpinfo(). The reason it was not reflecting in the phpinfo() echo, is because I was making the memory increase in the controller, and then echoing phpinfo() from the view, so the increase was not...

Function in C extension randomly stops python program execution

python,c,memory-management,random,python-c-extension

I figured out how to avoid the problem: The function ptrvectorInt, that shall allocate the memory for the output array, did not work properly. I replaced it by int **ptrvectorInt(long dim1) { int **v; if (!(v = malloc(dim1 * sizeof(int*)))) { PyErr_SetString(PyExc_MemoryError, "In **ptrvectorInt. Allocation of memory for integer array...

uninitialized data segment of program memory

memory-management,heap-memory

You seem to be asking about the difference between compile-time initialization and run-time initialization. In the following C code: int i; int main() { int j; return i + j; } i is a globally scoped variable and so is default initialized to zero, which is achieved by including it...

Deleting a dynamically allocated 2D array [duplicate]

c++,memory-management,delete-operator

In reality, an array of pointers pointed to by a pointer is still an array of integral data types or numbers to hold the memory addresses. You should use delete[] for both. Also, yes, a new[] implies a delete[]. When you create an array of arrays, you're actually creating an...

Is there a difference between new List() and new List(0)

c#,.net,list,memory-management

Here is the actual source code (Some parts trimmed for brevity) static readonly T[] _emptyArray = new T[0]; public List() { _items = _emptyArray; } public List(int capacity) { if (capacity < 0) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.capacity, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); Contract.EndContractBlock(); if (capacity == 0) _items = _emptyArray; else _items = new T[capacity]; } As...

How to free memory in C# that is allocated in C++

c#,c++,memory-management,dll,memory-leaks

You need to call the corresponding "free" method in the library you're using. Memory allocated via new is part of the C++ runtime, and calling FreeHGlobal won't work. You need to call (one way or the other) delete[] against the memory. If this is your own library then create a...

c - unsetenv() implementation, is it necessary to free memory?

c,memory-management,setenv

In your case it is not necessary if you don't plan to set your environment variables very frequently leading to exhaust of your memory resources. But it would be great if you always deallocate resources after you are done with using them, be it file handles/memory/mutexs. By doing so you...

How to have my program stops if its memory consumption exceeds a limit ?

c++,linux,memory-management

A simple mechanism for controlling a process's resource limits is provided by setrlimit. But that doesn't isolate the process (as you should for untrusted third-party code), it only puts some restrictions on it. To properly isolate a process from the rest of the system, you should either use a VM,...

Using Picasso to solve OutOfMemoryError

android,memory-management,out-of-memory,picasso

EDIT: well, you are using too much memory. remove those 3 lines of code : File imgFile = new File(data.get(position).get("path")); Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath()); imageView.setImageBitmap(myBitmap); simply, you are assigning too much space to these instances and your phone runs out of memory. Just use my response and consider logging the...

Multipart form uploads + memory leaks in golang?

memory-management,memory-leaks,go

If the memory usage stagnates at a "maximum", I wouldn't really call that a memory leak. I would rather say the GC not being eager and being lazy. Or just don't want to physically free memory if it is frequently reallocated / needed. If it would be really a memory...

Memory Management (Allocating Pages/Frames to Logical Addresses)

memory,memory-management,operating-system,paging,virtual-memory

If you have a page size of 4096, then page number = address DIV 4096 page offset = address MOD 4096 Those two values uniquely identify the logical memory location. Two addresses can be in the same frame. If that were not the case, there would be no point in...

Android - effective performance and memory management

java,android,memory-management,memory-leaks

Some java virtual machines, when creating small objects of known size, which is not viewed outside of it scope, creates object in stack, rather than in heap. For example oracle JVM after 7th version doing so. So it is may be more efficient to create small constant size temporary arrays...

Proper memory cleanup with c_str() and const char *

c++,memory-management,stdstring,const-char

It's a pointer to memory allocated in std::string. When the std::string falls out of scope, the memory is released. Be sure not to hold onto the pointer after that!

Convert IntPtr to char** in C#

c#,memory-management,types,type-conversion,dllimport

It should be something like: IntPtr di; int result = afc_read_directory(client, @"C:\", out di); if (di == IntPtr.Zero) { throw new Exception(); } IntPtr di2 = di; while (true) { IntPtr ptr = Marshal.ReadIntPtr(di2); if (ptr == IntPtr.Zero) { break; } string str = Marshal.PtrToStringAnsi(ptr); if (str == string.Empty) {...

physical memory userspace/kernel split on Linux x86-64

memory,memory-management,linux-kernel,kvm

No. Almost any physical page frame can be mapped to a userspace virtual address or a kernel virtual address, or even both at the same time....

Garbage Collector doesn't immediately collect finished thread [duplicate]

java,multithreading,memory-management,garbage-collection

Could it be that you are asking the wrong question? What I mean: is the fact that garbage collection is not happening "immediately" a problem for you? I am pretty sure - when you start another such thread that needs a lot of memory, the GC will kick in all...

Explanation of why allocating a large array results in segmentation fault in C [duplicate]

c,arrays,memory-management

It depends where you allocated the array. If it's inside a function, then the variable is allocated on the stack, and by default, (I assume you're running linux) the stack size is 8Mb. You can find it out using ulimit -s and also modify this value, for instance ulimit -s...

C# apps using ram and cannot be cleared

c#,memory-management

Even though you are disposing of the objects, the memory will only actually be released when the Garbage Collector runs. You can force this to happen explicitly by running the following code: GC.Collect(); GC.WaitForPendingFinalizers(); However, it's not recommended to do this yourself as the Garbage Collector is intended to run...