<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Failed to start advertising, err -12 (-ENOMEM)</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/123136/failed-to-start-advertising-err--12--enomem</link><description>Hi, 
 
 I&amp;#39;m working on an application that combines both central and peripheral roles. My &amp;#39;gateway&amp;#39; should connect to 2 peripherals and sometimes start advertising to make allow connecting to another central (called &amp;#39;central&amp;#39; going forward). I seem to</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sun, 27 Jul 2025 16:02:55 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/123136/failed-to-start-advertising-err--12--enomem" /><item><title>RE: Failed to start advertising, err -12 (-ENOMEM)</title><link>https://devzone.nordicsemi.com/thread/543667?ContentTypeID=1</link><pubDate>Sun, 27 Jul 2025 16:02:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:939b37fe-9217-461b-bf01-4c2788d07f6a</guid><dc:creator>WoutWG</dc:creator><description>&lt;p&gt;Making sure not to unref on_disconnect when acting as the peripheral indeed fixed the negative ref which caused the conn object to stay alive.&lt;/p&gt;
&lt;p&gt;Thanks Vidar!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Failed to start advertising, err -12 (-ENOMEM)</title><link>https://devzone.nordicsemi.com/thread/543204?ContentTypeID=1</link><pubDate>Tue, 22 Jul 2025 13:15:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aa2689b5-0ed3-4a1a-b1d5-69dbf346cdb2</guid><dc:creator>WoutWG</dc:creator><description>&lt;p&gt;Hi Vidar,&lt;/p&gt;
&lt;p&gt;Thank you for the feedback. Good to know that it&amp;#39;s not necessary to unref the conn object in the context of being the peripheral. I currently do the unref in the on_disconnect callback which is called in both instances,&amp;nbsp;for peripheral connection as well as for central connection. This would be what causes the negative reference count. I&amp;#39;ll test a workaround to see if removing this in the peripheral connection case would solve the issue, and let you know.&lt;/p&gt;
&lt;p&gt;Best,&lt;/p&gt;
&lt;p&gt;Wout&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Failed to start advertising, err -12 (-ENOMEM)</title><link>https://devzone.nordicsemi.com/thread/543163?ContentTypeID=1</link><pubDate>Tue, 22 Jul 2025 11:55:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5763b530-0035-4922-964f-dfadd02b5079</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hello Wout,&lt;/p&gt;
&lt;p&gt;I did not know that it was possible to get a negative reference count. But from what you describe it sounds like the problem is likely related to maintaining the correct connection reference count. For central connections, you&amp;nbsp;must release the reference on disconnect since the bt_conn_le_create()&amp;nbsp;takes one reference:&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1753185062183v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;For peripheral connection on the other hand it is only needed if you explicitly take a reference with bt_conn_ref() on the object in your code.&amp;nbsp;&lt;/p&gt;
[quote user=""]Alternatively, is there a way to start advertising without creating a new conn and reusing an older one?[/quote]
&lt;p&gt;It can&amp;#39;t be reused until it has been released.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;It&amp;#39;s also important that you don&amp;#39;t try to start the advertiser immediately from the disconnect callback as the connection object will not be freed at that point. We have updated our sample codes in the more recent SDK versions to always&amp;nbsp;restart the advertiser from the system workqueue.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Vidar&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>