Swift Memory Cycle From Closure

I am working with closures and want to confirm that I do not have any memory leaks in my code. Below is my current code:

// in ImageGalleryController.swift class ImageGalleryCollectionViewController: UICollectionViewController {   var images = [Image]()  func dropInteraction(_ interaction: UIDropInteraction, performDrop session: UIDropSession) {     // assignment of closure     var cellImage = Image() { [weak self](image) in       self?.images.append(image)       self?.collectionView.reloadData()     }     // asynchronous     session.loadObjects(ofClass: NSURL.self) { urls in       if let url = urls.first as? URL {         cellImage.url = url       }     }     // asynchronous     session.loadObjects(ofClass: UIImage.self) { images in       if let image = images.first as? UIImage {         cellImage.aspectRatio = Double(image.size.height / image.size.width)       }     }   } }  // in ImageGallery.swift struct Image {   var url: URL? = nil {     didSet {       if propertiesAreSet() { handler(self) }     }   }   var aspectRatio: Double? = nil {     didSet {       if propertiesAreSet() { handler(self) }     }   }    init(handler: @escaping (Image) -> Void) {     self.handler = handler   }    var handler: (Image) -> Void    private func propertiesAreSet() -> Bool {     let bool = (url != nil && aspectRatio != nil) ? true : false     return bool   } } 

Basically my logic is that when two separate asynchronous requests get and set two separate properties on the Image struct, then I want to append that Image struct to the images array.

Which brings me to my related questions:

  • Since I am fairly new to Swift, am I properly handling memory leaks by declaring [weak self] when I create a new Image instance?
  • Should I set the closure handler to nil after it executes?
  • Is what I am doing ok or am I violating any Swift principles?

Internal memory almost full

I’ve got Samsung Galaxy J5 with Marshmallow 6.0.1 and in this phone I’ve got internal memory of 8 gb and a memory card of 8gb. I’ve stored every little picture and audio in external memory and many apps too but the system memory takes up 3.28gb and the apps take 3.83gb and there’s no space left after that. I don’t know what to do I don’t even have many apps and games in this phone. Please help me on how to save up internal memory space without having to move everything to external memory?!!

what does “Memory access to address 00000030 looks like unallocated stack space.” warning mean? [on hold]

/nios 2 assembly language/

ADDR_SSEGNUMS: .word 0x4F5B063F, 0x077D6D66, 0x6F7F Arr: .hword 0x00000006 .hword 0x0000005B .hword 0x0000004F .hword 0x00000066 .hword 0x0000006D .hword 0x0000007D .hword 0x00000007 .hword 0x0000007F .hword 0x00000067

.global _start _start: /* initialize base addresses of parallel ports / movia r18, 0x10000000 / red LED base address / movia r19, 0x10000010 / green LED base address / movia r20, 0x10000020 / HEX3_HEX0 base address / movia r21, 0x10000030 / HEX4_HEX7 base address / movia r22, 0x10000050 / pushbutton KEY base address / movia r23, 0x10002000 / interval timer (onboard 50 MHz clock) base address */ movia r17, ADDR_SSEGNUMS movui r10, 10 movia r24, Arr movi r25, 9 movi r26, 0

/* load timer countdown value / movui r3, 0x02af / upper 16-bits of 500000 countdown value / sthio r3, 12(r23) / write to timer start value (high) register / movui r3, 0xf080 / lower 16-bits of 500000 countdown value / sthio r3, 8(r23) / write to timer start value (low) register */ movi r8, 0x4

/* start and continue timer countdown with no interrupts / movui r3, 0x6 / load timer control value / sthio r3, 4(r23) / write to timer control register */

PRESS_A_KEY_TO_START: /* press a pushbutton to start counter / ldwio r2, 0(r22) / load input from pushbuttons / stwio r2, 0(r19) / write to green LEDs */ ble r2, r8, PRESS_A_KEY_TO_START

/* monitor timeout signal to identify when the timer countdown ends (reach 0) / WAIT_FOR_TO_SIGNAL: ldhio r3, 0(r23) / load status register / andi r3, r3, 1 / load timeout (TO) bit / beq r3, r0, WAIT_FOR_TO_SIGNAL / wait until timer timeout (TO is set to 1) */

add r4, r4, r3 /* count number of timeouts */ divu r5, r4, r10 mul r5, r5, r10 sub r5, r4, r5 stwio r5, 0(r18) ble r5,r10, loop1

loop1: bge r26,r25,_start /* compare the size of the array with the counter / ldb r7,0(r24) / load the least significant bit / addi r24,r24,2 / increment / addi r26,r26,1
display: add r27, r7, r0
add r9, r7, r0 stwio r27, 0(r20) /
display the contents of r8 in the first four segment*/
movia r29, 1000000
DELAY: subi r29, r29, 4
bne r29, r0, DELAY /* shift the values of the register by 8 bits*/ stwio r27,0(r20)

        bne r29, r0, loop3          /* if register values are not equal go to loop3*/           

stwio r28, 0(r20) /* display count of timeouts on LEDR / stwio r0, 0(r23) / reset TO bit in status register */ br WAIT_FOR_TO_SIGNAL

Memory dump analysis

Please I would like your help as I am a newbie in this field. Trying to analyze a memory dump which contains text files. I use volatility an to be more specific the filescan command which outputs the text file I want to open but then I try to see the content without much success. My command looks like “volatility dump_file_path filescan | grep “*.txt” | cat” Do you have any idea what’s wrong?

Design pattern and/or data structure for cache friendly memory allocation?

I am a bit new to this site. Feel free to edit or move me to where I or question would fit better.

I am a applied mathematician / computational engineer searching for design patterns and data structures exist for cache-friendly memory allocation (for fast numerical floating point algorithms)?

For example I have N activities for which I want to group data to be local in memory when allocated as I know that when activity # k is executed it will greatly benefit if all of the data it uses is within one cache window.

KDE plasma using too much memory

I use Kubuntu 18.04. When I use it for a long time, opening and closing many applications, the memory usage goes up to 3gb and never comes down after closing all open applications. This issue is more likely to happen after copying a lot of files. In htop, I can see about 10 processes with name plasmashell, using the highest memory. How can I fix this memory leak? (I’m a noob)

Non-terminating php-fcgi causing lack of memory

I am running a quite large WordPress multisite installation with apache2 and php-fcgi. We are executing php-fcgi via a wrapper script because some time ago, we needed to support different versions.

I’ve got a problem that I do not know how to debug anymore: Over time, lots of php-fcgi instances spawn that never get killed. All multisites use more or less the same setup, but unfortunately they all run under the same user (not a good idea I know), so I cannot even track down if it’s one multisite or multiple causing the issue. This leads to extreme high memory usage until after some days, apache crashes.

This is the relevant part of the vhost setup:

Options All ExecCGI AddHandler fcgid-script .php  <Directory /..> Options -Indexes +FollowSymLinks +Includes +ExecCGI FCGIWrapper /*/php-fcgi/php-fcgi-starter .php </Directory> 

And this is the php-fcgi-starter:

#!/bin/sh PHPRC="**/conf/" export PHPRC export TMPDIR=**tmp exec /usr/bin/php-cgi 

Does anybody have an idea what the issue might be or how to debug this (e.g. pin it down to a specific script)? The logs are not helping.

Thank you so much.

Persistent Memory Emulation Platform (PMEP) [on hold]

has anyone used Persistent Memory Emulation Platform (PMEP)? It is supposed to be designed by Intel to simulate Non-Volatile Memory. It’s mentioned in a few articles but quite unclear how to get access to it. So any help and information would be appreciated.

Other suggestions for similar platforms would be helpful. I have found some of them but I am not sure which one is really useful. Besides read and write functions mainly I want to evaluate cache flushing instructions.

Reduce memory consumption of numpy function

I have a Numpy function that takes the values of an existing array X and a size (int) k equivalent to the columns of the array. This function does some calculations in a new array, to finally output the new array after the calculations are done.

def ff(x, k):     newarr = np.zeros((x.shape[0], 1), dtype=np.uint32)     newarr[:, 0] = x[:, 0] * 4     for i in range(1, k - 1):         newarr[:, 0] += x[:, i]         newarr[:, 0] = newarr[:, 0] * 4     newarr[:, 0] += x[:, -1]     return newarr 

newarr it’s the array where the calculated data is stored, it’s initialized with np.zeros and a dtype, and it has a shape of (y,1) where y is the length of the x array.

The first step is to store in the (only) column of the newarr the multiplication of the first column of the x by 4.

The iteration occurs over the columns 1 to k-1 of the original array (x). Inside the iteration, the next step is to sum the values of the first column of x to the column of newarr. Next, to multiply the column of newarr by 4 To finally, after the iteration is complete, sum the last column of the original array x to the column of newarr.

I’m looking for a way (if there’s any) to avoid the creation of the newarr, and do the calculations in the original array. This’, to reduce the memory usage of this function, mainly because the x tends to be very big in execution.

The x array looks like this.

array([[3, 3, 0, 1],        [3, 0, 1, 0],        [0, 1, 0, 2],        [1, 0, 2, 2],        [0, 2, 2, 3],        [2, 2, 3, 1],        [2, 3, 1, 3],        .        .        .        [2, 2, 0, 1]], dtype=uint8) 

In this case, the k value would be 4

Any additional improvement in the code is well received! Thanks for your time.