3,832 questions
1
vote
2
answers
83
views
Why defining string within a function scope allocates it on heap instead of a stack? [duplicate]
According this awesome article there is an interesting case with two given examples:
A:
B:
And there is an explanation for A:
Unfortunately you have not taken into account that such Strings will ...
0
votes
0
answers
59
views
Calling ARC code from non-ARC code causing EXC_BAD_ACCESS when autorelease pool drains
void test(void) {
@autoreleasepool {
NSDictionary *dict = copyDict();
NSLog(@"%lu", [dict retainCount]);
[dict release];
}
}
int main (int argc, const char * ...
1
vote
1
answer
143
views
How do I use Arc with interior mutability over slices?
MRE:
use std::sync::Arc;
use std::thread;
fn main() {
let arr1 = Arc::new(vec![10; 100]);
let arr2 = Arc::new(vec![20; 100]);
let arr3 = Arc::new(vec![00; 100]); // Going to need interior ...
0
votes
0
answers
59
views
NSObject proxy with weak delegate crashes with NSInvalidArgumentException unrecognized selector
I'm debugging a library that implements a UIScrollViewDelegate proxy (essentially) like:
class ScrollViewDelegateProxy: NSObject, UIScrollViewDelegate {
private weak var realDelegate: ...
2
votes
1
answer
71
views
Reference counting an uninitialized object
I have some Objective C code compiled with ARC:
void func(void) {
NSString *string;
// Do some stuff. Maybe return early.
string = @"initialized";
// Other stuff.
}
How ...
2
votes
1
answer
108
views
Arc: how to enable audio player for my own website?
I'm trying to enable the Arc browser audio player on a webpage of mine.
I cannot find any documentation from Arc targeted to developers though, so I tried by using what works for Google Chrome, but it ...
1
vote
2
answers
126
views
Should 'self' be explicitly specified in closure with weak reference to self in capture list?
DispatchQueue.main.async {
view.setNeedsLayout()
}
With above code we get expected error: Implicit use of 'self' in closure; use 'self.' to make capture semantics explicit.
It's known that the ...
0
votes
0
answers
44
views
ARC and the release of custom objects passed into async network methods
In my app I’m running into a problem leaking custom objects passed into a chain of methods that store HTML files into a custom object. Where each method finds a local copy of a file, the file is read ...
0
votes
2
answers
99
views
mutate dynamically sized vec in parallel
I'm trying to mutate a dynamically sized (i.e. under certain conditions, new values are pushed, and pop() gets called in every iteration) Vec in parallel. Am I doing anything wrong in this working ...
0
votes
0
answers
66
views
Deallocation for NSTextView in Objective-C
I am learning to create a Cocoa application on Mac OS and have run into an issue with memory I don't quite understand. From what I've read with non-ARC is that you should be releasing anything you've ...
0
votes
0
answers
27
views
Instantiating ONNX Session and Environment and overcoming borrowing error without having to use unsafe pointers [duplicate]
I have been trying to instantiate an ONNX runtime environment and session within a struct that can also contain all of the public methods I need. I have a working solution, however this requires the ...
0
votes
1
answer
71
views
Fill a matrix in parallel - how to convert `Vec<Arc<Mutex<Vec<_>>>>` to Vec<Vec<_>>`
I'm learning Rust and just finished the Fearless Concurrency chapter in the Rust book, so am trying to fill up the rows of a matrix in parallel.
My matrix is large, so I send a chunk of rows to each ...
1
vote
1
answer
279
views
How does the NSWindow isReleasedWhenClosed property work when using ARC?
In Objective-C with ARC or Swift (which always uses ARC), what difference does it make whether isReleasedWhenClosed is true or not? Won't a window be kept alive as long as my code has strong ...
0
votes
1
answer
417
views
Acquiring an access token using REST API on a ARC Connected VM
I'm wanting to connect a On-Prem VM to Azure KeyVault. I have installed the Azure Arc Agent successfully and can see the VM under ARC Machines in Azure.
However when I go to request the API token as ...
1
vote
1
answer
219
views
Is there a sound way to convert/transmute from Arc<String> to Arc<Vec<u8>>
String and Vec<u8> have the same memory layout, although this is not guaranteed.
String also has an into_bytes method returning a Vec<u8>.
Is there a sound way to convert from an Arc<...
1
vote
1
answer
65
views
Weak var in Swift Tree implementation
I am trying to build a tree implementation in Swift to represent a chess game.
A game consists of a sequence of moves but alternative moves for a given board position are valid. I want to traverse the ...
1
vote
1
answer
53
views
Why is a CALayer retained after I stop referencing it?
I've the impression that my CALayer is retained after being added as a sublayer until the end execution block, instead of until I stop referencing it.
The parent UIView is however released as soon as ...
0
votes
0
answers
65
views
Cocoa application produces a lot of "inactive" memory
I am developing software in Objective-C that reads files in chunks and processes them. I noticed with very large files it slows down a lot. Looking in activity monitor it's pretty clear what's going ...
1
vote
1
answer
175
views
UIImage does not release memory
The code below is to reproduce what I encountered.
After loading and cleaning data, the memory is still not freed.
And the weirdest thing is that if I press the clean data twice, the memory could be ...
0
votes
0
answers
218
views
Trouble with shared state updates between threads using Arc and Mutex in Rust
I'm working on a Rust application where I need to manage shared state between two threads using Arc and Mutex. The application has a Node struct that holds some data, and I'm trying to update this ...
2
votes
1
answer
122
views
Should I use `weak self` on a custom stored queue?
I know that we can use strong self in DispatchQueues when we call it directly in the code, for example:
func foo() {
DispatchQueue.global().async {
print(self.someProperty)
}
}
But ...
0
votes
0
answers
74
views
Sheet binded item doesn't deinitialize SwiftUI
Have the following scenario. Basically I want to use the item binded sheet init and bind it to an optional property which will be set when we want to show the sheet. On the outside it looks perfectly ...
1
vote
1
answer
75
views
How to make weak reference when setting function to closure variable
How to weak self when setting function to closure as in 1. to work same as example 2. Any ideas?
class TabController: UITabBarController {
func setupViewActions() {
tabView.itemTapped = changeTab //...
0
votes
1
answer
59
views
Borrowing issues using variables wrapped in Arc<Mutex<>> in Rust [duplicate]
The code below can work.
#[derive(Debug)]
struct Test{
str1 : Option<String>,
str2 : Option<String>,
}
fn main() {
let mut test = Test{
str1 : Some(String::from("...
0
votes
0
answers
43
views
Draw a ring using the HTML5 canvas without the straight line [duplicate]
I want to draw a ring with the canvas that doesn't have the straight black line you see when you use the below code.
var can = document.getElementById('canvas1');
var ctx = can.getContext('2d');
...
1
vote
0
answers
82
views
CCACHE is returning wrong result
I am using the Synopsis ARC compiler for a multi-core (two cores) application, and I have a startup.s file written in assembly. To distinguish the behavior for the application on different cores, I ...
1
vote
0
answers
31
views
Memory allocation in swift [duplicate]
In swift, based on Apple's documentation reference types are stored on heap and value types on stack, but if a class definition has a struct variable for example String, where will that be stored?
...
0
votes
0
answers
40
views
Counting Different cells that are the same for a list
I have to draw up panel setups for work and a lot of time goes into counting/listing how many of each panels there are, I've been looking into "count if" formulas and such with little ...
0
votes
1
answer
153
views
Tkinter canvas create arc sometimes displays incorrectly
First time submitting a question.
One of my object visualization programs uses arcs as a connector between lines. The starting angle and extent are calculated. With some combinations of angle and ...
1
vote
2
answers
899
views
Shared memory in Rust
Environment:
macOS Sonoma Ver.14.0 (M1 mac)
Rust Ver.1.65.0
What I want to do:
I want to share a vec with an array of [u8;128] elements between multithreads.
The requirements I want to perform when ...
0
votes
1
answer
165
views
Memory management issue while Call Obj-C in Swift
I'm currently developing a native plugin for a Capcitor app. I have very little experience with native iOS development, Swift and Obj-C.
I use a framework (FunSDK) which is written in C++.
I call this ...
4
votes
2
answers
195
views
Attaching arrows to SVG Arc path
I am creating a gauge using svg.
Is there a way to add an arrow at the end of the animated gauge to indicate the entered value?
Since the gauge is displayed with the path's stroke-dasharray, it seems ...
0
votes
0
answers
155
views
Enabling ARC (Automatic Reference Counting) in xamarin.ios project not working
I'm currently working on a Xamarin.iOS project, and I've enabled ARC (Automatic Reference Counting) using the following setting in the "Additional mtouch arguments" field on the iOS Build ...
0
votes
0
answers
89
views
Swift: Ensuring deinitialization of objects in arrary
I'm new to Swift's ARC and I'm having a possibly memory problem with the following swift code:
class Device {
let name: String
var ports: [Port]
init(name: String, ports: [Port] = []) {
...
1
vote
1
answer
2k
views
Rust struct field as arc vs. struct as arc
I have a question regarding the Arc in Rust. I want to do something with multi-threading and stumbled on Arcs to give multiple threads access to the same data. At the moment, I use a struct with the ...
0
votes
1
answer
102
views
How can I store automatic reference counted Swift/Objective-C objects in a C++ map without causing memory leaks when they are deleted from the map?
I have a C++ map which manages loaded regions. Each region has an associated MTLBuffer for the geometry generated after the region data is converted into a mesh. The idea is to store a reference to ...
0
votes
0
answers
40
views
Reference data from collection data in one ViewModel as another ViewModels data [duplicate]
I currently have 2 classes. One of them is named DeckManager and holds Deck objects inside an Array collection named decks (Each Deck contains an array of Card objects).
The next Class is named ...
0
votes
1
answer
224
views
Is using SnapKit causing memory leaks
I am using SnapKit to handle my AutoLayout. I am wondering does this code cause a memory leak because I am capturing self in a closure?
writtenUpSwitch.snp.makeConstraints {
$0.trailing....
0
votes
1
answer
452
views
Why doesn't delegate work in SwiftUI with UIViewControllerRepresentable?
Here's a sample code snippet for a video player in SwiftUI, where the player's core is implemented in UIKit (specifically in PlayerViewController):
struct Page: View {
let delegate = Delegate()
...
1
vote
0
answers
105
views
Remix Arc Sandbox - handler is not a function Error
Tried running Remix app in Arc sandbox via this command: node ./dev sandbox after doing npx remix build.
It starts a sandbox in port 3001 when accessed in the browser it throws this error:
Lambda ...
3
votes
2
answers
348
views
Is it possible to convert a &[T] or Vec<T> to Arc<Mutex<[T]>>?
Consider the following
use std::sync::{Arc,Mutex};
fn arc_mutex_from_slice<T>(v: &[T]) -> Arc<Mutex<[T]>> {
todo!();
}
fn main() {
let v = vec![1,2,3];
println!(&...
1
vote
2
answers
271
views
Swift Class Deallocation Not Happening
I am writing a SwiftUI based Mac OS app that show a list of added files and allows the user to select them, and remove one or more selected files from the list, or remove everything from the list.
To ...
0
votes
1
answer
58
views
Centering a String Based on a Dynamically Changing Arc
I'm in my first year of computer engineering, learning Java as my first programming language. I wanted to create a 'Fast Wheel Raffle' application, but I encountered a few issues. First of all:
1- I'm ...
4
votes
0
answers
156
views
How do I prevent an arbitrary object's destructor from ever running in Python?
Context
I have a troublesome object from third-party code in a Python (3.10) program. The object is not written in pure Python; it's provided by an extension module.
Due to a bug in the third party ...
1
vote
0
answers
454
views
Avoid cycle Arc references without Weak in Rust
I know that the data inside an Arc is stored in heap, and when two objects have Arc reference to each other, they would not be dropped automatically by compiler. The following code shows this case.
...
0
votes
2
answers
392
views
Lock-free concurrent field usage
Say I have the following struct:
struct MyStruct {
field1: Box<MyField>,
field2: Box<MyField>,
}
and I'd like to be able to do the following:
Use the fields in separate threads in ...
0
votes
1
answer
1k
views
Rust: Cannot borrow data in `Arc` as mutable, but inner data is protected via Mutex [closed]
While learning Rust, and trying to work through an example wherein a database Db is required to be shared across threads and functions.
Link To Minimal Example
I have wrapped the database (a struct) ...
0
votes
1
answer
204
views
d3.js version 7 - pie and arc - Error: <path> attribute d: Expected number, "…LNaN,NaNZ"
I'm trying to do a spin wheel with d3.js. Everything worked fine with the old version 3. The pies and arcs didn't have any problem. When switching to d3.js v5 or later, i've got an omnipresent NaN in ...
1
vote
1
answer
83
views
Automatic Reference Counting in Swift
I have a question about ARC in Swift, please take a look at the following code.
When SecondViewController is presented, the alert will pop up, and once you click "OK" button,
...
2
votes
2
answers
488
views
Is a strong reference cycle created in this simple case of using URLSession?
I'm a little confused about how strong references are created and when reference cycles occur. Here's a simple example:
class Model {
var foo: Data?
func makeRequest(url: URL) {
...