Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7688881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:01:49+00:00 2026-05-31T20:01:49+00:00

This might be a silly question but does ARC (automatic reference counting) interact with

  • 0

This might be a silly question but does ARC (automatic reference counting) interact with Open CV when programming in the iOS?

I am asking this because I just recently started using Open CV in general. While on iOS with ARC it is not necessary to worry about objects since I only have to make sure to have no pointers pointing at them so that they can be released.

Open CV seems to have a similar cleaning function:

http://opencv.willowgarage.com/documentation/cpp/memory_management.html

When using the new interface, the most of memory deallocation and even
memory allocation operations are done automatically when needed.

First, does this means I don’t have to release those objects?

Second, I am using both OpenCV and Objective C in the same .mm file. Is it safe to assume that the objects won’t be messing with each other?

For example this will give me an UIImage from a cv Mat:

+ (UIImage *)imageWithCVMat:(const cv::Mat&)cvMat
{
    return [[UIImage alloc] initWithCVMat:cvMat];
}

Which uses this:

- (id)initWithCVMat:(const cv::Mat&)cvMat
{
    NSData *data = [NSData dataWithBytes:cvMat.data length:cvMat.elemSize() * cvMat.total()];

    CGColorSpaceRef colorSpace;

    if (cvMat.elemSize() == 1)
    {
        colorSpace = CGColorSpaceCreateDeviceGray();
    }
    else
    {
        colorSpace = CGColorSpaceCreateDeviceRGB();
    }

    CGDataProviderRef provider = CGDataProviderCreateWithCFData((__bridge CFDataRef)data);

    CGImageRef imageRef = CGImageCreate(cvMat.cols,                                     // Width
                                        cvMat.rows,                                     // Height
                                        8,                                              // Bits per component
                                        8 * cvMat.elemSize(),                           // Bits per pixel
                                        cvMat.step[0],                                  // Bytes per row
                                        colorSpace,                                     // Colorspace
                                        kCGImageAlphaNone | kCGBitmapByteOrderDefault,  // Bitmap info flags
                                        provider,                                       // CGDataProviderRef
                                        NULL,                                           // Decode
                                        false,                                          // Should interpolate
                                        kCGRenderingIntentDefault);                     // Intent   

    self = [self initWithCGImage:imageRef];
    CGImageRelease(imageRef);
    CGDataProviderRelease(provider);
    CGColorSpaceRelease(colorSpace);

    return self;
}

*method taken from Robin Summerhill

Thanks in advance for any advice.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T20:01:50+00:00Added an answer on May 31, 2026 at 8:01 pm

    First, does this means I don’t have to release those objects?

    Yes, until you create them using new operator. Look at this code:

    {
    cv::Mat image(640,480); // allocate image
    //.. do something with it
    self.myImage = [UIImage imageWithCVMat:image];
    }
    // Out of scope - image is deallocated automatically.
    // But self.myImage is still accessible since it contains a copy of image.
    

    Second, I am using both OpenCV and Objective C in the same .mm file. Is it safe to assume that the objects won’t be messing with each other?

    In your initWithCVMat functiton the image data is copied to NSData object which is used to initialize a new instance of UIImage.

    For you it means:
    1) An instance of UIImage class will be responsible of releasing image data. If you use ARC – it will be done automatically; otherwise you have to call [UIImage release].
    2) Don’t worry about cv::Mat – it will release memory automatically when destroyed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

All, This might be a very silly question, but in a Programming lang X
This might be a silly question, but still I am going ahead and asking
This might be a bit of a silly question but; If I have two
This might be a silly question: Does HTTP ever use the User Datagram Protocol?
This might be a silly question but it struck me, and here i ask.
This might be a silly question but I am still learning. I have read
This might be a silly question, but I'm a beginner in C#, so please
This might seem to be a silly question at first, but please read on.
I've just started programming with Java, so might appear as silly question, but I
This question might seem really silly to most of the enlightened folks here. But

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.